-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
500 changed files
with
10,343 additions
and
49,361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
if [ -n "$(gofmt -l .)" ]; then | ||
echo "Go code is not formatted:" | ||
gofmt -d . | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
WDIR=$PWD | ||
|
||
for f in *; do | ||
if [ -d "$f" ]; then | ||
cd $WDIR/"$f" | ||
go test -v -race ./... | ||
cd $WDIR | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
sudo: false | ||
language: go | ||
os: | ||
- linux | ||
- osx | ||
go: | ||
- 1.14.x | ||
- go1.15.x | ||
env: | ||
global: | ||
- GO111MODULE=on | ||
- GOPROXY=https://goproxy.io | ||
before_install: | ||
- chmod +x .travis.gofmt.sh | ||
- chmod +x .travis.gotest.sh | ||
script: | ||
- ./.travis.gofmt.sh | ||
- ./.travis.gotest.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Swagger 2.0 | ||
|
||
Visit https://github.com/iris-contrib/swagger instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/iris-contrib/examples/apidoc/yaag | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/betacraft/yaag v1.0.1-0.20200719063524-47d781406108 | ||
github.com/kataras/iris/v12 v12.1.9-0.20200812051831-0edf0affb0bd | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/kataras/iris/v12" | ||
|
||
"github.com/betacraft/yaag/irisyaag" | ||
"github.com/betacraft/yaag/yaag" | ||
) | ||
|
||
type myXML struct { | ||
Result string `xml:"result"` | ||
} | ||
|
||
func main() { | ||
app := iris.New() | ||
|
||
yaag.Init(&yaag.Config{ // <- IMPORTANT, init the middleware. | ||
On: true, | ||
DocTitle: "Iris", | ||
DocPath: "apidoc.html", | ||
BaseUrls: map[string]string{"Production": "", "Staging": ""}, | ||
}) | ||
app.Use(irisyaag.New()) // <- IMPORTANT, register the middleware. | ||
|
||
app.Get("/json", func(ctx iris.Context) { | ||
ctx.JSON(iris.Map{"result": "Hello World!"}) | ||
}) | ||
|
||
app.Get("/plain", func(ctx iris.Context) { | ||
ctx.Text("Hello World!") | ||
}) | ||
|
||
app.Get("/xml", func(ctx iris.Context) { | ||
ctx.XML(myXML{Result: "Hello World!"}) | ||
}) | ||
|
||
app.Get("/complex", func(ctx iris.Context) { | ||
value := ctx.URLParam("key") | ||
ctx.JSON(iris.Map{"value": value}) | ||
}) | ||
|
||
// Run our HTTP Server. | ||
// | ||
// Documentation of "yaag" doesn't note the follow, but in Iris we are careful on what | ||
// we provide to you. | ||
// | ||
// Each incoming request results on re-generation and update of the "apidoc.html" file. | ||
// Recommentation: | ||
// Write tests that calls those handlers, save the generated "apidoc.html". | ||
// Turn off the yaag middleware when in production. | ||
// | ||
// Example usage: | ||
// Visit all paths and open the generated "apidoc.html" file to see the API's automated docs. | ||
app.Listen(":8080") | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Package main integrates the "rs/cors" net/http middleware into Iris. | ||
// That cors third-party middleware cannot be registered through `iris.FromStd` | ||
// as a common middleware because it should be injected before the Iris Router itself, | ||
// it allows/dissallows HTTP Methods too. | ||
// | ||
// This is just an example you can use to run something, based on custom logic, | ||
// before the Iris Router itself. | ||
// | ||
// In the "routing/custom-wrapper" example | ||
// we learn how we can acquire and release an Iris context to fire an Iris Handler | ||
// based on custom logic, before the Iris Router itself. In that example | ||
// we will fire a net/http handler (the "rs/cors" handler one) instead. | ||
// | ||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS | ||
package main | ||
|
||
import ( | ||
"github.com/kataras/iris/v12" | ||
"github.com/rs/cors" | ||
) | ||
|
||
func main() { | ||
app := iris.New() | ||
c := cors.New(cors.Options{ | ||
AllowedOrigins: []string{"*"}, | ||
AllowCredentials: true, | ||
// Enable Debugging for testing, consider disabling in production | ||
Debug: true, | ||
}) | ||
// app.WrapRouter(func(w http.ResponseWriter, r *http.Request, router http.HandlerFunc) { | ||
// [custom logic...] | ||
// if shouldFireNetHTTPHandler { | ||
// ...ServeHTTP(w,r) | ||
// return | ||
// } | ||
// router(w,r) | ||
// }) | ||
// In our case, the cors package has a ServeHTTP | ||
// of the same form of app.WrapRouter's accept input argument, | ||
// so we can just do: | ||
app.WrapRouter(c.ServeHTTP) | ||
|
||
// Serve ./public/index.html, main.js. | ||
app.HandleDir("/", iris.Dir("./public")) | ||
|
||
// Register routes here... | ||
app.Get("/data", listData) | ||
|
||
// http://localhost:8080 and click the "fetch data" button. | ||
app.Listen(":8080") | ||
} | ||
|
||
type item struct { | ||
Title string `json:"title"` | ||
} | ||
|
||
func listData(ctx iris.Context) { | ||
ctx.JSON([]item{ | ||
{"Item 1"}, | ||
{"Item 2"}, | ||
{"Item 3"}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Iris Cors Example</title> | ||
</head> | ||
|
||
<body> | ||
<ul id="list"> | ||
</ul> | ||
|
||
<input type="button" value="Fetch Data" id="fetchBtn" /> | ||
|
||
<script src="main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch | ||
async function doRequest(method = 'GET', url = '', data = {}) { | ||
// Default options are marked with * | ||
|
||
const request = { | ||
method: method, // *GET, POST, PUT, DELETE, etc. | ||
mode: 'cors', // no-cors, *cors, same-origin | ||
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached | ||
credentials: 'same-origin', // include, *same-origin, omit | ||
redirect: 'follow', // manual, *follow, error | ||
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url | ||
}; | ||
|
||
if (data !== undefined && method !== 'GET' && method !== 'HEAD') { | ||
request.headers = { | ||
'Content-Type': 'application/json' | ||
// 'Content-Type': 'application/x-www-form-urlencoded', | ||
}; | ||
// body data type must match "Content-Type" header. | ||
request.body = JSON.stringify(data); | ||
} | ||
|
||
const response = await fetch(url, request); | ||
return response.json(); // parses JSON response into native JavaScript objects. | ||
} | ||
|
||
const ul = document.getElementById("list"); | ||
|
||
function fetchData() { | ||
console.log("sending request...") | ||
|
||
doRequest('GET', '/data').then(data => { | ||
data.forEach(item => { | ||
var li = document.createElement("li"); | ||
li.appendChild(document.createTextNode(item.title)); | ||
ul.appendChild(li); | ||
}); | ||
|
||
console.log(data); // JSON data parsed by `response.json()` call. | ||
}); | ||
} | ||
|
||
document.getElementById("fetchBtn").onclick = fetchData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generate RSA | ||
|
||
```sh | ||
$ openssl genrsa -des3 -out private_rsa.pem 2048 | ||
``` | ||
|
||
```go | ||
b, err := ioutil.ReadFile("./private_rsa.pem") | ||
if err != nil { | ||
panic(err) | ||
} | ||
key := jwt.MustParseRSAPrivateKey(b, []byte("pass")) | ||
``` | ||
|
||
OR | ||
|
||
```go | ||
import "crypto/rand" | ||
import "crypto/rsa" | ||
|
||
key, err := rsa.GenerateKey(rand.Reader, 2048) | ||
``` | ||
|
||
# Generate Ed25519 | ||
|
||
```sh | ||
$ openssl genpkey -algorithm Ed25519 -out private_ed25519.pem | ||
$ openssl req -x509 -key private_ed25519.pem -out cert_ed25519.pem -days 365 | ||
``` |
Oops, something went wrong.