This commit is contained in:
2025-09-20 18:12:56 -04:00
parent 2fba07f4b3
commit 08e1191ba3
3 changed files with 78 additions and 63 deletions

View File

@@ -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"],