-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from AAStarCommunity/dylan/feature/v0.1-executor
Dylan/feature/v0.1 executor
- Loading branch information
Showing
12 changed files
with
145 additions
and
80 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
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,27 @@ | ||
package api | ||
|
||
import ( | ||
"AAStarCommunity/EthPaymaster_BackService/conf" | ||
"AAStarCommunity/EthPaymaster_BackService/rpc_server/models" | ||
"github.com/gin-gonic/gin" | ||
"time" | ||
) | ||
|
||
// Healthz | ||
// @Tags Healthz | ||
// @Description Get Healthz | ||
// @Accept json | ||
// @Product json | ||
// @Param | ||
// @Router /api/health [post,get,put,delete] | ||
// @Success 200 | ||
func Healthz(c *gin.Context) { | ||
response := models.GetResponse() | ||
response.WithDataSuccess(c, gin.H{ | ||
"hello": "Eth Paymaster", | ||
"environment": conf.Environment.Name, | ||
"time": time.Now(), | ||
"version": "v1.0.0", | ||
}) | ||
response.Success(c) | ||
} |
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,10 @@ | ||
package middlewares | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// LogHandler log handler | ||
func LogHandler() gin.HandlerFunc { | ||
return gin.Logger() | ||
} |
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
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
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
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,32 +1,23 @@ | ||
package routers | ||
|
||
import ( | ||
"AAStarCommunity/EthPaymaster_BackService/rpc_server/api" | ||
"AAStarCommunity/EthPaymaster_BackService/rpc_server/middlewares" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// buildRouters Build Routers | ||
func buildRouters(router *gin.Engine) { | ||
|
||
router.POST("api/auth", api.Auth) | ||
|
||
router.Use(middlewares.AuthHandler()) | ||
{ | ||
router.Use(middlewares.RateLimiterByApiKey()) | ||
|
||
for _, routerMap := range RouterMaps { | ||
for _, method := range routerMap.Methods { | ||
if method == GET { | ||
router.GET(routerMap.Url, routerMap.Func) | ||
} else if method == PUT { | ||
router.PUT(routerMap.Url, routerMap.Func) | ||
} else if method == POST { | ||
router.POST(routerMap.Url, routerMap.Func) | ||
} else if method == DELETE { | ||
router.DELETE(routerMap.Url, routerMap.Func) | ||
} // ignore rest methods | ||
} | ||
func buildRouters(router *gin.Engine, routerMaps []RouterMap) { | ||
for _, routerMap := range routerMaps { | ||
for _, method := range routerMap.Methods { | ||
if method == GET { | ||
router.GET(routerMap.Url, routerMap.Func) | ||
} else if method == PUT { | ||
router.PUT(routerMap.Url, routerMap.Func) | ||
} else if method == POST { | ||
router.POST(routerMap.Url, routerMap.Func) | ||
} else if method == DELETE { | ||
router.DELETE(routerMap.Url, routerMap.Func) | ||
} // ignore rest methods | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
package routers | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
type RestfulMethod string | ||
|
||
const ( | ||
PUT RestfulMethod = "PUT" | ||
GET RestfulMethod = "GET" | ||
DELETE RestfulMethod = "DELETE" | ||
POST RestfulMethod = "POST" | ||
HEAD RestfulMethod = "HEAD" | ||
OPTIONS RestfulMethod = "OPTIONS" | ||
) | ||
|
||
type RouterMap struct { | ||
Url string | ||
Methods []RestfulMethod | ||
Func func(ctx *gin.Context) | ||
} |
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 @@ | ||
package routers | ||
|
||
import "testing" | ||
|
||
func TestConst(t *testing.T) { | ||
|
||
t.Logf("%s", string(TryPayUserOperation)) | ||
} |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
package routers | ||
|
||
import ( | ||
"AAStarCommunity/EthPaymaster_BackService/rpc_server/api" | ||
v1 "AAStarCommunity/EthPaymaster_BackService/rpc_server/api/v1" | ||
) | ||
|
||
var PrivateRouterMaps []RouterMap | ||
var PublicRouterMaps []RouterMap | ||
|
||
func init() { | ||
PrivateRouterMaps = make([]RouterMap, 0) | ||
|
||
PrivateRouterMaps = append(PrivateRouterMaps, RouterMap{string(TryPayUserOperation), []RestfulMethod{POST}, v1.TryPayUserOperation}) | ||
PrivateRouterMaps = append(PrivateRouterMaps, RouterMap{string(GetSupportStrategy), []RestfulMethod{GET}, v1.GetSupportStrategy}) | ||
PrivateRouterMaps = append(PrivateRouterMaps, RouterMap{string(GetSupportEntrypoint), []RestfulMethod{GET}, v1.GetSupportEntrypoint}) | ||
PublicRouterMaps = append(PublicRouterMaps, RouterMap{string(Auth), []RestfulMethod{POST}, api.Auth}) | ||
PublicRouterMaps = append(PublicRouterMaps, RouterMap{string(Healthz), []RestfulMethod{GET, HEAD, OPTIONS}, api.Healthz}) | ||
} | ||
|
||
type Path string | ||
|
||
const ( | ||
TryPayUserOperation Path = "api/v1/try-pay-user-operation" | ||
GetSupportStrategy Path = "api/v1/get-support-strategy" | ||
GetSupportEntrypoint Path = "api/v1/get-support-entrypoint" | ||
Auth Path = "api/auth" | ||
Healthz Path = "api/healthz" | ||
) |