forked from openGemini/opengemini-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support new OpenGemini client with config
Signed-off-by: PennyYoon <525296438@qq.com>
- Loading branch information
1 parent
2a41447
commit 26af5fc
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |