clean
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -17,13 +19,19 @@ type ConfigDef struct {
|
||||
}
|
||||
|
||||
type BaseConfig struct {
|
||||
ServerAddress string `json:"address" description:"Conduit server address" default:"http://localhost:8080"`
|
||||
ServerAddress string `json:"server" description:"Conduit server address" default:"http://localhost:8080"`
|
||||
APIKey string `json:"api_key" description:"API Key for the conduit API"`
|
||||
}
|
||||
|
||||
func (c *BaseConfig) Validate() error {
|
||||
if c.APIKey == "" {
|
||||
return fmt.Errorf("api_key is required")
|
||||
return errors.New("api_key is required")
|
||||
}
|
||||
if c.ServerAddress == "" {
|
||||
return errors.New("server is required")
|
||||
}
|
||||
if _, err := url.Parse(c.ServerAddress); err != nil {
|
||||
return fmt.Errorf("server is invalid: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -78,7 +86,7 @@ func GetClientConfig(cmdFlags *pflag.FlagSet) (*ClientConfig, error) {
|
||||
|
||||
cfg := &ClientConfig{
|
||||
BaseConfig: BaseConfig{
|
||||
ServerAddress: cfgValues["address"],
|
||||
ServerAddress: cfgValues["server"],
|
||||
APIKey: cfgValues["api_key"],
|
||||
},
|
||||
TunnelName: cfgValues["name"],
|
||||
|
||||
Reference in New Issue
Block a user