Skip to content

Commit

Permalink
Merge pull request #2 from 1ch0/dev
Browse files Browse the repository at this point in the history
Feat: add config set
  • Loading branch information
1ch0 authored Aug 2, 2023
2 parents f3c0c66 + 6cec676 commit ad7ec42
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ type Client struct {
}

type Config struct {
Addr string
Username string
Password string
Version string `yaml:"version"`
Addr string `yaml:"addr"`
Scheme string `yaml:"scheme"`
IP string `yaml:"ip"`
Port string `yaml:"port"`
Username string `yaml:"username"`
Password string `yaml:"password"`
}

type authentication struct {
Expand All @@ -34,14 +38,24 @@ type authentication struct {

func New(config *Config) *Client {
return &Client{
Config: config,
Config: config.set(),
authentication: &authentication{},
client: resty.New().SetTimeout(5 * time.Second).SetDisableWarn(true).SetRetryCount(3),
httpMethod: "",
iPath: "",
error: nil}
}

func (c *Config) set() *Config {
if c.Addr == "" {
if c.Scheme != "" {
c.Addr = fmt.Sprintf("%s://%s:%s", c.Scheme, c.IP, c.Port)
}
c.Addr = fmt.Sprintf("http://%s:%s", c.IP, c.Port)
}
return c
}

// Health 检查服务是否健康
func (c *Client) Health() error {
_, err := c.client.R().Get(c.Config.Addr)
Expand Down

0 comments on commit ad7ec42

Please sign in to comment.