Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support new OpenGemini client with config #4

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions opengemini/client.go
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
package opengemini

import (
"crypto/tls"
)

const (
AuthTypeToken AuthType = iota
AuthTypePassword
)

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

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)
}
36 changes: 36 additions & 0 deletions opengemini/client_impl.go
Original file line number Diff line number Diff line change
@@ -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 == AuthTypeToken && len(c.AuthConfig.Token) == 0 {
return nil, errors.New("invalid auth config due to empty token")
}
if c.AuthConfig.AuthType == AuthTypePassword {
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
}
Loading