working commit

This commit is contained in:
2026-05-30 12:04:50 +02:00
parent c5ed2b2245
commit c964adce89
9 changed files with 37 additions and 28 deletions
-4
View File
@@ -32,13 +32,10 @@ EXTRA_mproxyd_SOURCES += \
app/config/config.go \ app/config/config.go \
app/config/variant.go \ app/config/variant.go \
app/handler/aaafunc.go \ app/handler/aaafunc.go \
app/handler/account.go \
app/handler/grant.go \
app/handler/handler.go \ app/handler/handler.go \
app/handler/notfound.go \ app/handler/notfound.go \
app/handler/response.go \ app/handler/response.go \
app/handler/service.go \ app/handler/service.go \
app/locker/locker.go \
app/logger/logger.go \ app/logger/logger.go \
app/router/bindobj.go \ app/router/bindobj.go \
app/router/context.go \ app/router/context.go \
@@ -48,7 +45,6 @@ EXTRA_mproxyd_SOURCES += \
app/router/recovermw.go \ app/router/recovermw.go \
app/router/router.go \ app/router/router.go \
app/server/server.go \ app/server/server.go \
app/server/listen.go \
app/service/service.go \ app/service/service.go \
\ \
app/servoper/operator.go \ app/servoper/operator.go \
+6 -8
View File
@@ -359,15 +359,13 @@ EXTRA_mproxyctl_SOURCES = \
mproxyd_SOURCES = cmd/mproxyd/main.go mproxyd_SOURCES = cmd/mproxyd/main.go
EXTRA_mproxyd_SOURCES = cmd/mproxyd/starter/starter.go \ EXTRA_mproxyd_SOURCES = cmd/mproxyd/starter/starter.go \
app/config/config.go app/config/variant.go \ app/config/config.go app/config/variant.go \
app/handler/aaafunc.go app/handler/account.go \ app/handler/aaafunc.go app/handler/handler.go \
app/handler/grant.go app/handler/handler.go \
app/handler/notfound.go app/handler/response.go \ app/handler/notfound.go app/handler/response.go \
app/handler/service.go app/locker/locker.go \ app/handler/service.go app/logger/logger.go \
app/logger/logger.go app/router/bindobj.go \ app/router/bindobj.go app/router/context.go \
app/router/context.go app/router/corsmw.go \ app/router/corsmw.go app/router/loggingmw.go \
app/router/loggingmw.go app/router/pathc.go \ app/router/pathc.go app/router/recovermw.go \
app/router/recovermw.go app/router/router.go \ app/router/router.go app/server/server.go \
app/server/server.go app/server/listen.go \
app/service/service.go app/servoper/operator.go \ app/service/service.go app/servoper/operator.go \
app/servoper/service.go pkg/auxhttp/basic.go \ app/servoper/service.go pkg/auxhttp/basic.go \
pkg/auxhttp/crange.go pkg/auxpwd/passwd.go \ pkg/auxhttp/crange.go pkg/auxpwd/passwd.go \
+2 -2
View File
@@ -63,7 +63,7 @@ func (svc *Service) Build() error {
svc.rout.Use(router.NewCorsMiddleware()) svc.rout.Use(router.NewCorsMiddleware())
svc.rout.Use(svc.hand.AuthMiddleware) 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) 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) svc.logg.Infof("%s\t%s", item.Method, item.RawPath)
} }
const useTLS = false const useTLS = true
if useTLS { if useTLS {
tlsCert, err := tls.X509KeyPair([]byte(svc.x509cert), []byte(svc.x509key)) tlsCert, err := tls.X509KeyPair([]byte(svc.x509cert), []byte(svc.x509key))
+2 -3
View File
@@ -9,7 +9,6 @@ import (
) )
const ( 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" 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.Password, "pass", "P", util.commonServiceParams.Password, "Password")
subCmd.PersistentFlags().StringVarP(&util.commonServiceParams.Hostname, "host", "X", defaultHostname, "Hostname") subCmd.PersistentFlags().StringVarP(&util.commonServiceParams.Hostname, "host", "X", defaultHostname, "Hostname")
subCmd.PersistentFlags().Uint64VarP(&util.commonServiceParams.Timeout, "timeout", "T", defaultTimeout, "Operation timeout") 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") subCmd.MarkFlagsRequiredTogether("user", "pass")
vi := viper.New() vi := viper.New()
@@ -53,7 +52,7 @@ func (util *ServiceUtil) MakeServiceCmds() *cobra.Command {
// GetService // GetService
var getservcmd = &cobra.Command{ var getservcmd = &cobra.Command{
Use: "get [user:pass@]hostname[:port]", Use: "hello [user:pass@]hostname[:port]",
Short: "Get service hello", Short: "Get service hello",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
Run: util.GetHello, Run: util.GetHello,
+7 -2
View File
@@ -23,7 +23,10 @@ func (util *ServiceUtil) GetHello(cmd *cobra.Command, args []string) {
printResponse(res, err) 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) { func (util *ServiceUtil) getHello(common *CommonServiceParams, params *GetHelloParams) (*GetHelloResult, error) {
var err error var err error
@@ -38,9 +41,11 @@ func (util *ServiceUtil) getHello(common *CommonServiceParams, params *GetHelloP
ref.SetUserinfo(common.Username, common.Password) ref.SetUserinfo(common.Username, common.Password)
mw := servcli.NewBasicAuthMiddleware(ref.Userinfo()) mw := servcli.NewBasicAuthMiddleware(ref.Userinfo())
cli := servcli.NewClient(nil, mw) cli := servcli.NewClient(nil, mw)
err = cli.GetHello(ctx, ref.Raw()) operRes, err := cli.GetHello(ctx, ref.Raw())
if err != nil { if err != nil {
return res, err return res, err
} }
res.Message = operRes.Message
res.Alive = operRes.Alive
return res, err return res, err
} }
+1 -1
View File
@@ -30,7 +30,7 @@ func (util *Util) Build() error {
execName := filepath.Base(os.Args[0]) execName := filepath.Base(os.Args[0])
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: execName, Use: execName,
Short: "\nGet hello from service", Short: "\nSupport tools",
SilenceUsage: true, SilenceUsage: true,
} }
rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.CompletionOptions.DisableDefaultCmd = true
+3 -1
View File
@@ -267,7 +267,9 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo
dist_man1_MANS = \ dist_man1_MANS = \
mproxyctl.1 mproxyctl.1 \
mproxyctl-service.1 \
mproxyctl-service-get.1
dist_man8_MANS = \ dist_man8_MANS = \
mproxyd.8 mproxyd.8
+15 -6
View File
@@ -11,21 +11,30 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"mproxy/app/handler"
"mproxy/app/servoper" "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 var err error
req := servoper.GetHelloParams{} req := servoper.GetHelloParams{}
res := servoper.GetHelloResult{}
reqdata, err := json.Marshal(req) reqdata, err := json.Marshal(req)
if err != nil { if err != nil {
return err return res, err
} }
_, err = cli.DoCall(ctx, rawpath, reqdata) resdata, err := cli.DoCall(ctx, rawpath, reqdata)
if err != nil { 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) { 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 return res, err
} }
req.Header.Set("User-Agent", cli.userAgent) req.Header.Set("User-Agent", cli.userAgent)
req.Header.Set("Accept", "*/*") req.Header.Set("Accept", "application/json")
resp, err := cli.httpClient.Do(req) resp, err := cli.httpClient.Do(req)
if err != nil { if err != nil {
return res, err return res, err
+1 -1
View File
@@ -72,7 +72,7 @@ func (ref *Referer) DryRun(yesno bool) {
} }
func (ref *Referer) HelloEP() string { 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() return curl.String()
} }