-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (43 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"github.com/donetkit/contrib-gin/middleware/httpsign"
"github.com/donetkit/contrib-gin/middleware/httpsign/crypto"
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
// Define algorithm
hmacsha256 := &crypto.HmacSha256{}
hmacsha512 := &crypto.HmacSha512{}
// Init define secret params
readKeyID := httpsign.KeyID("read")
writeKeyID := httpsign.KeyID("write")
secrets := httpsign.Secrets{
readKeyID: &httpsign.Secret{
Key: "HMACSHA256-SecretKey",
Algorithm: hmacsha256, // You could using other algo with interface Crypto
},
writeKeyID: &httpsign.Secret{
Key: "HMACSHA512-SecretKey",
Algorithm: hmacsha512,
},
}
// Init webserve
r := gin.Default()
//Create middleware with default rule. Could modify by parse Option func
auth := httpsign.NewAuthenticator(secrets)
r.Use(auth.Authenticated())
r.GET("/a", a)
r.POST("/b", b)
r.POST("/c", c)
r.Run(":8080")
}
func c(c *gin.Context) {
c.String(http.StatusOK, "OK")
}
func b(c *gin.Context) {
c.String(http.StatusOK, "OK")
}
func a(c *gin.Context) {
c.String(http.StatusOK, "OK")
}