summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-03-17 17:57:51 +0700
committerShulhan <ms@kilabit.info>2024-03-18 21:55:35 +0700
commitb86893f6dd315cb253ec5479501791c500d82876 (patch)
tree2122d00405271e4f8a5ac4f048693562d17a4319
parent182a79905737010fa135d101be656144b7b0f39a (diff)
downloadhaminer-b86893f6dd315cb253ec5479501791c500d82876.tar.xz
all: rename the forwarder files by using prefix "forwarder_"
-rw-r--r--config_forwarder.go13
-rw-r--r--config_test.go3
-rw-r--r--forwarder_influxd.go (renamed from influxd_client.go)18
-rw-r--r--forwarder_questdb.go (renamed from questdb_client.go)16
-rw-r--r--haminer.go12
5 files changed, 33 insertions, 29 deletions
diff --git a/config_forwarder.go b/config_forwarder.go
index c53b807..0bc3cf9 100644
--- a/config_forwarder.go
+++ b/config_forwarder.go
@@ -14,12 +14,13 @@ const (
influxdVersion1 = `v1`
influxdVersion2 = `v2`
- forwarderInfluxd = `influxd`
- forwarderQuestdb = `questdb`
+ forwarderKindInfluxd = `influxd`
+ forwarderKindQuestdb = `questdb`
)
// ConfigForwarder contains configuration for forwarding the logs.
type ConfigForwarder struct {
+ kind string
Version string `ini:"::version"`
URL string `ini:"::url"`
@@ -28,12 +29,12 @@ type ConfigForwarder struct {
Bucket string `ini:"::bucket"`
- // Fields for HTTP API v1.
+ // Fields for Influxd HTTP API v1.
User string `ini:"::user"`
Pass string `ini:"::pass"`
- // Fields for HTTP API v2.
+ // Fields for Influxd HTTP API v2.
Org string `ini:"::org"`
Token string `ini:"::token"`
@@ -41,11 +42,13 @@ type ConfigForwarder struct {
// init check, validate, and initialize the configuration values.
func (cfg *ConfigForwarder) init(fwName string) (err error) {
+ cfg.kind = fwName
+
if len(cfg.URL) == 0 {
return
}
- if fwName == forwarderInfluxd {
+ if fwName == forwarderKindInfluxd {
return cfg.initInfluxd()
}
diff --git a/config_test.go b/config_test.go
index f2b7e96..a54e18d 100644
--- a/config_test.go
+++ b/config_test.go
@@ -64,7 +64,8 @@ func TestLoad(t *testing.T) {
in: "testdata/haminer.conf",
exp: &Config{
Forwarders: map[string]*ConfigForwarder{
- `influxd`: &ConfigForwarder{
+ forwarderKindInfluxd: &ConfigForwarder{
+ kind: forwarderKindInfluxd,
Version: `v2`,
URL: `http://127.0.0.1:8086`,
Org: `kilabit.info`,
diff --git a/influxd_client.go b/forwarder_influxd.go
index 481f641..3ee358c 100644
--- a/influxd_client.go
+++ b/forwarder_influxd.go
@@ -17,21 +17,21 @@ const (
defContentType = "application/octet-stream"
)
-// InfluxdClient contains HTTP connection for writing logs to Influxd.
-type InfluxdClient struct {
+// forwarderInfluxd contains HTTP connection for writing logs to Influxd.
+type forwarderInfluxd struct {
conn *http.Client
cfg *ConfigForwarder
hostname string
buf bytes.Buffer
}
-// NewInfluxdClient will create, initialize, and return new Influxd client.
-func NewInfluxdClient(cfg *ConfigForwarder) (cl *InfluxdClient) {
+// newForwarderInfluxd will create, initialize, and return new Influxd client.
+func newForwarderInfluxd(cfg *ConfigForwarder) (cl *forwarderInfluxd) {
if len(cfg.URL) == 0 {
return nil
}
- cl = &InfluxdClient{
+ cl = &forwarderInfluxd{
cfg: cfg,
}
@@ -41,7 +41,7 @@ func NewInfluxdClient(cfg *ConfigForwarder) (cl *InfluxdClient) {
return
}
-func (cl *InfluxdClient) initHostname() {
+func (cl *forwarderInfluxd) initHostname() {
var err error
cl.hostname, err = os.Hostname()
@@ -53,7 +53,7 @@ func (cl *InfluxdClient) initHostname() {
}
}
-func (cl *InfluxdClient) initConn() {
+func (cl *forwarderInfluxd) initConn() {
tr := &http.Transport{}
cl.conn = &http.Client{
@@ -63,7 +63,7 @@ func (cl *InfluxdClient) initConn() {
// Forwards implement the Forwarder interface. It will write all logs to
// Influxd.
-func (cl *InfluxdClient) Forwards(halogs []*HTTPLog) {
+func (cl *forwarderInfluxd) Forwards(halogs []*HTTPLog) {
var (
logp = `influxdClient: Forwards`
@@ -120,7 +120,7 @@ func (cl *InfluxdClient) Forwards(halogs []*HTTPLog) {
fmt.Printf(`%s: response: %d %s\n`, logp, httpRes.StatusCode, rspBody)
}
-func (cl *InfluxdClient) write(halogs []*HTTPLog) (err error) {
+func (cl *forwarderInfluxd) write(halogs []*HTTPLog) (err error) {
var (
l *HTTPLog
k string
diff --git a/questdb_client.go b/forwarder_questdb.go
index d185978..5903e1d 100644
--- a/questdb_client.go
+++ b/forwarder_questdb.go
@@ -18,21 +18,21 @@ const (
defQuestdbPort = 9009
)
-// questdbClient client for questdb.
-type questdbClient struct {
+// forwarderQuestdb client for questdb.
+type forwarderQuestdb struct {
conn net.Conn
buf bytes.Buffer
}
-// newQuestdbClient create and initialize client connection using the URL in
+// newForwarderQuestdb create and initialize client connection using the URL in
// the ConfigForwarder.
-func newQuestdbClient(cfg *ConfigForwarder) (questc *questdbClient, err error) {
+func newForwarderQuestdb(cfg *ConfigForwarder) (questc *forwarderQuestdb, err error) {
if cfg == nil || len(cfg.URL) == 0 {
return nil, nil
}
var (
- logp = `newQuestdbClient`
+ logp = `newForwarderQuestdb`
timeout = 10 * time.Second
surl *url.URL
@@ -57,7 +57,7 @@ func newQuestdbClient(cfg *ConfigForwarder) (questc *questdbClient, err error) {
address = fmt.Sprintf(`%s:%d`, address, port)
}
- questc = &questdbClient{}
+ questc = &forwarderQuestdb{}
questc.conn, err = net.DialTimeout(surl.Scheme, address, timeout)
if err != nil {
@@ -69,9 +69,9 @@ func newQuestdbClient(cfg *ConfigForwarder) (questc *questdbClient, err error) {
// Forwards implement the Forwarder interface.
// It will write all logs to questdb.
-func (questc *questdbClient) Forwards(logs []*HTTPLog) {
+func (questc *forwarderQuestdb) Forwards(logs []*HTTPLog) {
var (
- logp = `questdbClient: Forwards`
+ logp = `forwarderQuestdb: Forwards`
now = time.Now()
httpLog *HTTPLog
diff --git a/haminer.go b/haminer.go
index 7d866a5..b89b619 100644
--- a/haminer.go
+++ b/haminer.go
@@ -71,19 +71,19 @@ func (h *Haminer) createForwarder() {
)
for fwName, fwCfg = range h.cfg.Forwarders {
- var influxc *InfluxdClient
+ var influxc *forwarderInfluxd
switch fwName {
- case forwarderInfluxd:
- influxc = NewInfluxdClient(fwCfg)
+ case forwarderKindInfluxd:
+ influxc = newForwarderInfluxd(fwCfg)
if influxc != nil {
h.ff = append(h.ff, influxc)
}
- case forwarderQuestdb:
- var questc *questdbClient
+ case forwarderKindQuestdb:
+ var questc *forwarderQuestdb
- questc, err = newQuestdbClient(fwCfg)
+ questc, err = newForwarderQuestdb(fwCfg)
if err != nil {
log.Printf(`%s: %s: %s`, logp, fwName, err)
continue