diff --git a/opengemini/client.go b/opengemini/client.go index e6fe79d..1bcab42 100644 --- a/opengemini/client.go +++ b/opengemini/client.go @@ -1 +1,47 @@ package opengemini + +import ( + "crypto/tls" +) + +var _, _ = NewClient(&Config{}) + +type Client interface { +} + +type Config struct { + AddressList []*Address + AuthConfig *AuthConfig + BatchConfig *BatchConfig + GzipEnabled bool + TlsConfig *tls.Config +} + +type Address struct { + Host string + Port int +} + +type AuthType int + +const ( + Password AuthType = iota + Token +) + +type AuthConfig struct { + AuthType AuthType + Username string + Password string + Token string +} + +type BatchConfig struct { + BatchEnabled bool + BatchInterval int + BatchSize int +} + +func NewClient(config *Config) (Client, error) { + return newClient(config) +} diff --git a/opengemini/client_impl.go b/opengemini/client_impl.go new file mode 100644 index 0000000..f8f8b9f --- /dev/null +++ b/opengemini/client_impl.go @@ -0,0 +1,36 @@ +package opengemini + +import "errors" + +type client struct { + config *Config +} + +func newClient(c *Config) (Client, error) { + if len(c.AddressList) == 0 { + return nil, errors.New("must have at least one address") + } + if c.AuthConfig.AuthType == Token && len(c.AuthConfig.Token) == 0 { + return nil, errors.New("invalid auth config due to empty token") + } + if c.AuthConfig.AuthType == Password { + if len(c.AuthConfig.Username) == 0 { + return nil, errors.New("invalid auth config due to empty username") + } + if len(c.AuthConfig.Password) == 0 { + return nil, errors.New("invalid auth config due to empty password") + } + } + if c.BatchConfig.BatchEnabled { + if c.BatchConfig.BatchInterval <= 0 { + return nil, errors.New("batch enabled, batch interval must be great than 0") + } + if c.BatchConfig.BatchSize <= 0 { + return nil, errors.New("batch enabled, batch size must be great than 0") + } + } + client := &client{ + config: c, + } + return client, nil +}