code refactor: move struct ReaderOptions to config

This commit is contained in:
Ulric Qin 2022-06-07 18:00:11 +08:00
parent 3e475e7e08
commit e5c1641b6b
2 changed files with 21 additions and 21 deletions

View File

@ -14,7 +14,6 @@ import (
"github.com/didi/nightingale/v5/src/pkg/httpx" "github.com/didi/nightingale/v5/src/pkg/httpx"
"github.com/didi/nightingale/v5/src/pkg/logx" "github.com/didi/nightingale/v5/src/pkg/logx"
"github.com/didi/nightingale/v5/src/pkg/ormx" "github.com/didi/nightingale/v5/src/pkg/ormx"
"github.com/didi/nightingale/v5/src/server/reader"
"github.com/didi/nightingale/v5/src/storage" "github.com/didi/nightingale/v5/src/storage"
) )
@ -136,10 +135,27 @@ type Config struct {
DB ormx.DBConfig DB ormx.DBConfig
WriterOpt WriterGlobalOpt WriterOpt WriterGlobalOpt
Writers []WriterOptions Writers []WriterOptions
Reader reader.Options Reader ReaderOptions
Ibex Ibex Ibex Ibex
} }
type ReaderOptions struct {
Url string
BasicAuthUser string
BasicAuthPass string
Timeout int64
DialTimeout int64
TLSHandshakeTimeout int64
ExpectContinueTimeout int64
IdleConnTimeout int64
KeepAlive int64
MaxConnsPerHost int
MaxIdleConns int
MaxIdleConnsPerHost int
}
type WriterOptions struct { type WriterOptions struct {
Url string Url string
BasicAuthUser string BasicAuthUser string

View File

@ -5,34 +5,18 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/didi/nightingale/v5/src/server/config"
"github.com/prometheus/client_golang/api" "github.com/prometheus/client_golang/api"
) )
type Options struct {
Url string
BasicAuthUser string
BasicAuthPass string
Timeout int64
DialTimeout int64
TLSHandshakeTimeout int64
ExpectContinueTimeout int64
IdleConnTimeout int64
KeepAlive int64
MaxConnsPerHost int
MaxIdleConns int
MaxIdleConnsPerHost int
}
type ReaderType struct { type ReaderType struct {
Opts Options Opts config.ReaderOptions
Client API Client API
} }
var Reader ReaderType var Reader ReaderType
func Init(opts Options) error { func Init(opts config.ReaderOptions) error {
cli, err := api.NewClient(api.Config{ cli, err := api.NewClient(api.Config{
Address: opts.Url, Address: opts.Url,
RoundTripper: &http.Transport{ RoundTripper: &http.Transport{