fixes
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
package goapi
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
import "crypto"
|
||||
|
||||
var perms map[string]string
|
||||
|
||||
func init() {
|
||||
perms = make(map[string]string)
|
||||
|
||||
perms["POST_/someapi"] = "ASD"
|
||||
|
||||
perms["DELETE_/someapi"] = "ASD"
|
||||
|
||||
perms["GET_/someapi"] = "ASD"
|
||||
|
||||
perms["PUT_/someapi"] = "ASD"
|
||||
|
||||
}
|
||||
|
||||
func GetPerm(c *gin.Context) string {
|
||||
perm, ok := perms[c.Request.Method+"_"+c.Request.URL.Path]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return perm
|
||||
}
|
||||
|
||||
func Build(r *gin.Engine) *gin.Engine {
|
||||
|
||||
r.DELETE("/someapi", func(c *gin.Context) {
|
||||
var req *crypto.Hash
|
||||
c.BindJSON(req)
|
||||
res, err := SomeAPI2(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
}
|
||||
c.JSON(200, res)
|
||||
})
|
||||
r.GET("/someapi", func(c *gin.Context) {
|
||||
var req string
|
||||
c.BindJSON(&req)
|
||||
res, err := SomeGET(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
}
|
||||
c.JSON(200, res)
|
||||
})
|
||||
r.POST("/someapi", func(c *gin.Context) {
|
||||
var req string
|
||||
c.BindJSON(&req)
|
||||
res, err := SomeAPI(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
}
|
||||
c.JSON(200, res)
|
||||
})
|
||||
r.PUT("/someapi", func(c *gin.Context) {
|
||||
var req string
|
||||
c.BindJSON(&req)
|
||||
res, err := SomePUT(c.Request.Context(), req)
|
||||
if err != nil {
|
||||
c.Error(err)
|
||||
}
|
||||
c.JSON(200, res)
|
||||
})
|
||||
|
||||
return r
|
||||
}
|
||||
+37
-36
@@ -25,42 +25,43 @@ type AStr struct {
|
||||
@PERM: ASD
|
||||
@VERB: POST
|
||||
*/
|
||||
func SomeAPI(ctx context.Context, s string) (out string, err error) {
|
||||
print("Got:" + s)
|
||||
out = time.Now().String() + " - Hey Ya!"
|
||||
func SomeAPI(ctx context.Context, s *AStr) (out *AStr, err error) {
|
||||
//print("Got:" + s)
|
||||
//out = time.Now().String() + " - Hey Ya!"
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
@API
|
||||
@PATH: /someapi
|
||||
@PERM: ASD
|
||||
@VERB: GET
|
||||
*/
|
||||
func SomeGET(ctx context.Context, s string) (out string, err error) {
|
||||
print("Got:" + s)
|
||||
out = time.Now().String() + " - Hey Ya!"
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
@API
|
||||
@PATH: /someapi
|
||||
@PERM: ASD
|
||||
@VERB: PUT
|
||||
*/
|
||||
func SomePUT(ctx context.Context, s string) (out string, err error) {
|
||||
print("Got:" + s)
|
||||
out = time.Now().String() + " - Hey Ya!"
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
@API
|
||||
@PATH: /someapi
|
||||
@PERM: ASD
|
||||
@VERB: DELETE
|
||||
*/
|
||||
func SomeAPI2(ctx context.Context, s *crypto.Hash) ([]string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
//
|
||||
///*
|
||||
//@API
|
||||
//@PATH: /someapi
|
||||
//@PERM: ASD
|
||||
//@VERB: GET
|
||||
//*/
|
||||
//func SomeGET(ctx context.Context, s string) (out string, err error) {
|
||||
// print("Got:" + s)
|
||||
// out = time.Now().String() + " - Hey Ya!"
|
||||
// return
|
||||
//}
|
||||
//
|
||||
///*
|
||||
//@API
|
||||
//@PATH: /someapi
|
||||
//@PERM: ASD
|
||||
//@VERB: PUT
|
||||
//*/
|
||||
//func SomePUT(ctx context.Context, s string) (out string, err error) {
|
||||
// print("Got:" + s)
|
||||
// out = time.Now().String() + " - Hey Ya!"
|
||||
// return
|
||||
//}
|
||||
//
|
||||
///*
|
||||
//@API
|
||||
//@PATH: /someapi
|
||||
//@PERM: ASD
|
||||
//@VERB: DELETE
|
||||
//*/
|
||||
//func SomeAPI2(ctx context.Context, s *crypto.Hash) ([]string, error) {
|
||||
// return nil, nil
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user