working commit
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"mstore/app/operator"
|
||||
"mstore/app/router"
|
||||
)
|
||||
@@ -10,5 +12,6 @@ func (hand *Handler) SendHello(rctx *router.Context) {
|
||||
|
||||
params := &operator.SendHelloParams{}
|
||||
res, _ := hand.oper.SendHello(params)
|
||||
rctx.SetStatus(http.StatusOK)
|
||||
hand.SendResult(rctx, res)
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
Ctx context.Context
|
||||
Request *http.Request
|
||||
Writer http.ResponseWriter
|
||||
PathMap map[string]string
|
||||
StatusCode int
|
||||
Ctx context.Context
|
||||
Request *http.Request
|
||||
Writer http.ResponseWriter
|
||||
PathMap map[string]string
|
||||
StatusCode int
|
||||
}
|
||||
|
||||
func NewContext(writer http.ResponseWriter, request *http.Request) *Context {
|
||||
@@ -30,7 +30,7 @@ func (rctx *Context) SetHeader(key, value string) {
|
||||
}
|
||||
|
||||
func (rctx *Context) SetStatus(httpStatus int) {
|
||||
rctx.StatusCode = httpStatus
|
||||
rctx.StatusCode = httpStatus
|
||||
rctx.Writer.WriteHeader(httpStatus)
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,11 @@ func (svc *Service) Build() error {
|
||||
svc.logg.Infof("Service build ")
|
||||
|
||||
svc.rout = router.NewRouter()
|
||||
|
||||
svc.rout.Use(router.NewRecoveryMiddleware(svc.logg.Errorf))
|
||||
svc.rout.Use(router.NewLoggingMiddleware(svc.logg.Infof))
|
||||
svc.rout.Use(router.NewCorsMiddleware())
|
||||
|
||||
svc.rout.Get("/v3/api/service/hello", svc.hand.SendHello)
|
||||
|
||||
svc.rout.Head("/v3/api/file/{filepath}", svc.hand.FileExists)
|
||||
|
||||
Reference in New Issue
Block a user