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

Revert "Init branch" #2

Closed
wants to merge 1 commit into from
Closed
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
123 changes: 0 additions & 123 deletions opengemini/client.go
Original file line number Diff line number Diff line change
@@ -1,124 +1 @@
package 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)
WritePoint(point Point)
//WriteLineProtocol()
//Query()
}

func (c *Client) WriteBatchPoint(points BatchPoints) {
//TODO implement me
panic("implement me")
}

func (c *Client) WritePoint(point Point) {
//TODO implement me
panic("implement me")
}
Loading