Skip to content

Commit

Permalink
feat: support new OpenGemini client with options
Browse files Browse the repository at this point in the history
Signed-off-by: PennyYoon <525296438@qq.com>
  • Loading branch information
Chenxulin97 committed Nov 13, 2023
1 parent 2a41447 commit bfc8686
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions opengemini/client.go
Original file line number Diff line number Diff line change
@@ -1 +1,124 @@
package opengemini

Check failure on line 1 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/openGemini/opengemini-client-go/opengemini

import (
"crypto/tls"
"errors"
)

var _ OpenGemini = (*Client)(nil)

type Options = func(client *Client) error

type Client struct {
Addresses []*Address
AuthConfig *AuthConfig
BatchConfig *BatchConfig
GzipEnable bool
TlsConfig *tls.Config
}

func NewClient(addresses []*Address, options ...Options) (*Client, error) {
client := new(Client)
if len(addresses) == 0 {
return nil, errors.New("must have at least one address")
}
client.Addresses = addresses
for _, op := range options {
err := op(client)
if err != nil {
return nil, err
}
}
return client, nil
}

func WithPassword(username, password string) Options {
return func(client *Client) error {
client.AuthConfig = &AuthConfig{
AuthType: Password,
UserName: username,
Password: password,
}
return nil
}
}

func WithToken(token string) Options {
return func(client *Client) error {
client.AuthConfig = &AuthConfig{
AuthType: Token,
Token: token,
}
return nil
}
}

func WithGzipEnable(enable bool) Options {
return func(client *Client) error {
client.GzipEnable = enable
return nil
}
}

func WithBatchConfig(enable bool, size, interval int) Options {
return func(client *Client) error {
if enable && (size <= 0 || interval <= 0) {
return errors.New("if batch enable , size and interval must more than 0")
}
client.BatchConfig = &BatchConfig{
enable,
interval,
size,
}
return nil
}
}

func WithTlsConfig(tls *tls.Config) Options {
return func(client *Client) error {
client.TlsConfig = tls
return nil
}
}

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 {
BatchEnable bool
BatchInterval int
BatchSize int
}

type OpenGemini interface {
WriteBatchPoint(points BatchPoints)

Check failure on line 110 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / lint

undefined: BatchPoints

Check failure on line 110 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / build

undefined: BatchPoints
WritePoint(point Point)

Check failure on line 111 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / lint

undefined: Point

Check failure on line 111 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / build

undefined: Point
//WriteLineProtocol()
//Query()
}

func (c *Client) WriteBatchPoint(points BatchPoints) {

Check failure on line 116 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / lint

undefined: BatchPoints

Check failure on line 116 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / build

undefined: BatchPoints
//TODO implement me
panic("implement me")
}

func (c *Client) WritePoint(point Point) {

Check failure on line 121 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / lint

undefined: Point (typecheck)

Check failure on line 121 in opengemini/client.go

View workflow job for this annotation

GitHub Actions / build

undefined: Point
//TODO implement me
panic("implement me")
}

0 comments on commit bfc8686

Please sign in to comment.