working commit
This commit is contained in:
@@ -32,13 +32,10 @@ EXTRA_mproxyd_SOURCES += \
|
||||
app/config/config.go \
|
||||
app/config/variant.go \
|
||||
app/handler/aaafunc.go \
|
||||
app/handler/account.go \
|
||||
app/handler/grant.go \
|
||||
app/handler/handler.go \
|
||||
app/handler/notfound.go \
|
||||
app/handler/response.go \
|
||||
app/handler/service.go \
|
||||
app/locker/locker.go \
|
||||
app/logger/logger.go \
|
||||
app/router/bindobj.go \
|
||||
app/router/context.go \
|
||||
@@ -48,7 +45,6 @@ EXTRA_mproxyd_SOURCES += \
|
||||
app/router/recovermw.go \
|
||||
app/router/router.go \
|
||||
app/server/server.go \
|
||||
app/server/listen.go \
|
||||
app/service/service.go \
|
||||
\
|
||||
app/servoper/operator.go \
|
||||
|
||||
+6
-8
@@ -359,15 +359,13 @@ EXTRA_mproxyctl_SOURCES = \
|
||||
mproxyd_SOURCES = cmd/mproxyd/main.go
|
||||
EXTRA_mproxyd_SOURCES = cmd/mproxyd/starter/starter.go \
|
||||
app/config/config.go app/config/variant.go \
|
||||
app/handler/aaafunc.go app/handler/account.go \
|
||||
app/handler/grant.go app/handler/handler.go \
|
||||
app/handler/aaafunc.go app/handler/handler.go \
|
||||
app/handler/notfound.go app/handler/response.go \
|
||||
app/handler/service.go app/locker/locker.go \
|
||||
app/logger/logger.go app/router/bindobj.go \
|
||||
app/router/context.go app/router/corsmw.go \
|
||||
app/router/loggingmw.go app/router/pathc.go \
|
||||
app/router/recovermw.go app/router/router.go \
|
||||
app/server/server.go app/server/listen.go \
|
||||
app/handler/service.go app/logger/logger.go \
|
||||
app/router/bindobj.go app/router/context.go \
|
||||
app/router/corsmw.go app/router/loggingmw.go \
|
||||
app/router/pathc.go app/router/recovermw.go \
|
||||
app/router/router.go app/server/server.go \
|
||||
app/service/service.go app/servoper/operator.go \
|
||||
app/servoper/service.go pkg/auxhttp/basic.go \
|
||||
pkg/auxhttp/crange.go pkg/auxpwd/passwd.go \
|
||||
|
||||
@@ -63,7 +63,7 @@ func (svc *Service) Build() error {
|
||||
svc.rout.Use(router.NewCorsMiddleware())
|
||||
svc.rout.Use(svc.hand.AuthMiddleware)
|
||||
|
||||
svc.rout.Get(`/v3/api/service/hello`, svc.hand.GetHello)
|
||||
svc.rout.Post(`/v3/api/service/hello`, svc.hand.GetHello)
|
||||
|
||||
svc.rout.Connect(``, svc.hand.ConnectTo)
|
||||
|
||||
@@ -80,7 +80,7 @@ func (svc *Service) Build() error {
|
||||
svc.logg.Infof("%s\t%s", item.Method, item.RawPath)
|
||||
}
|
||||
|
||||
const useTLS = false
|
||||
const useTLS = true
|
||||
if useTLS {
|
||||
tlsCert, err := tls.X509KeyPair([]byte(svc.x509cert), []byte(svc.x509key))
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
uuidRegex = `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`
|
||||
defaultHostname = "localhost:1025"
|
||||
)
|
||||
|
||||
@@ -41,7 +40,7 @@ func (util *ServiceUtil) MakeServiceCmds() *cobra.Command {
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonServiceParams.Password, "pass", "P", util.commonServiceParams.Password, "Password")
|
||||
subCmd.PersistentFlags().StringVarP(&util.commonServiceParams.Hostname, "host", "X", defaultHostname, "Hostname")
|
||||
subCmd.PersistentFlags().Uint64VarP(&util.commonServiceParams.Timeout, "timeout", "T", defaultTimeout, "Operation timeout")
|
||||
subCmd.PersistentFlags().BoolVarP(&util.commonServiceParams.SkipTLSVerify, "skipVerify", "S", true, "Skip server certificate verify")
|
||||
//subCmd.PersistentFlags().BoolVarP(&util.commonServiceParams.SkipTLSVerify, "skipVerify", "S", true, "Skip server certificate verify")
|
||||
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||
|
||||
vi := viper.New()
|
||||
@@ -53,7 +52,7 @@ func (util *ServiceUtil) MakeServiceCmds() *cobra.Command {
|
||||
|
||||
// GetService
|
||||
var getservcmd = &cobra.Command{
|
||||
Use: "get [user:pass@]hostname[:port]",
|
||||
Use: "hello [user:pass@]hostname[:port]",
|
||||
Short: "Get service hello",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.GetHello,
|
||||
|
||||
@@ -23,7 +23,10 @@ func (util *ServiceUtil) GetHello(cmd *cobra.Command, args []string) {
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type GetHelloResult struct{}
|
||||
type GetHelloResult struct {
|
||||
Message string `json:"message"`
|
||||
Alive bool `json:"alive"`
|
||||
}
|
||||
|
||||
func (util *ServiceUtil) getHello(common *CommonServiceParams, params *GetHelloParams) (*GetHelloResult, error) {
|
||||
var err error
|
||||
@@ -38,9 +41,11 @@ func (util *ServiceUtil) getHello(common *CommonServiceParams, params *GetHelloP
|
||||
ref.SetUserinfo(common.Username, common.Password)
|
||||
mw := servcli.NewBasicAuthMiddleware(ref.Userinfo())
|
||||
cli := servcli.NewClient(nil, mw)
|
||||
err = cli.GetHello(ctx, ref.Raw())
|
||||
operRes, err := cli.GetHello(ctx, ref.Raw())
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Message = operRes.Message
|
||||
res.Alive = operRes.Alive
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func (util *Util) Build() error {
|
||||
execName := filepath.Base(os.Args[0])
|
||||
rootCmd := &cobra.Command{
|
||||
Use: execName,
|
||||
Short: "\nGet hello from service",
|
||||
Short: "\nSupport tools",
|
||||
SilenceUsage: true,
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
+3
-1
@@ -267,7 +267,9 @@ top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo
|
||||
dist_man1_MANS = \
|
||||
mproxyctl.1
|
||||
mproxyctl.1 \
|
||||
mproxyctl-service.1 \
|
||||
mproxyctl-service-get.1
|
||||
|
||||
dist_man8_MANS = \
|
||||
mproxyd.8
|
||||
|
||||
+15
-6
@@ -11,21 +11,30 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"mproxy/app/handler"
|
||||
"mproxy/app/servoper"
|
||||
)
|
||||
|
||||
func (cli *Client) GetHello(ctx context.Context, rawpath string) error {
|
||||
func (cli *Client) GetHello(ctx context.Context, rawpath string) (servoper.GetHelloResult, error) {
|
||||
var err error
|
||||
|
||||
req := servoper.GetHelloParams{}
|
||||
res := servoper.GetHelloResult{}
|
||||
reqdata, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
_, err = cli.DoCall(ctx, rawpath, reqdata)
|
||||
resdata, err := cli.DoCall(ctx, rawpath, reqdata)
|
||||
if err != nil {
|
||||
return err
|
||||
return res, err
|
||||
}
|
||||
return err
|
||||
response := handler.NewResponse[servoper.GetHelloResult]()
|
||||
err = json.Unmarshal(resdata, &response)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = response.Result
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (cli *Client) DoCall(ctx context.Context, rawpath string, reqdata []byte) ([]byte, error) {
|
||||
@@ -43,7 +52,7 @@ func (cli *Client) DoCall(ctx context.Context, rawpath string, reqdata []byte) (
|
||||
return res, err
|
||||
}
|
||||
req.Header.Set("User-Agent", cli.userAgent)
|
||||
req.Header.Set("Accept", "*/*")
|
||||
req.Header.Set("Accept", "application/json")
|
||||
resp, err := cli.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return res, err
|
||||
|
||||
@@ -72,7 +72,7 @@ func (ref *Referer) DryRun(yesno bool) {
|
||||
}
|
||||
|
||||
func (ref *Referer) HelloEP() string {
|
||||
curl := ref.urlobj.JoinPath("/v3/api/service/hello", ref.resource)
|
||||
curl := ref.urlobj.JoinPath("/v3/api/service/hello")
|
||||
return curl.String()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user