52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
/*
|
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
|
*/
|
|
package servcmd
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"mproxy/pkg/servcli"
|
|
)
|
|
|
|
// GetHello
|
|
type GetHelloParams struct {
|
|
Address string
|
|
}
|
|
|
|
func (util *ServiceUtil) GetHello(cmd *cobra.Command, args []string) {
|
|
util.getHelloParams.Address = args[0]
|
|
res, err := util.getHello(&util.commonServiceParams, &util.getHelloParams)
|
|
printResponse(res, err)
|
|
}
|
|
|
|
type GetHelloResult struct {
|
|
Message string `json:"message"`
|
|
Alive bool `json:"alive"`
|
|
}
|
|
|
|
func (util *ServiceUtil) getHello(common *CommonServiceParams, params *GetHelloParams) (*GetHelloResult, error) {
|
|
var err error
|
|
res := &GetHelloResult{}
|
|
|
|
timeout := time.Duration(common.Timeout) * time.Second
|
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
|
ref, err := servcli.ParsePath(params.Address)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
ref.SetUserinfo(common.Username, common.Password)
|
|
mw := servcli.NewBasicAuthMiddleware(ref.Userinfo())
|
|
cli := servcli.NewClient(nil, mw)
|
|
operRes, err := cli.GetHello(ctx, ref.Raw())
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
res.Message = operRes.Message
|
|
res.Alive = operRes.Alive
|
|
return res, err
|
|
}
|