Skip to content

Commit

Permalink
[sync] Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Jan 17, 2025
1 parent a0d0100 commit 083ab1c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
15 changes: 3 additions & 12 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ package api
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"github.com/essentialkaos/ek/v13/req"

CORE "github.com/essentialkaos/rds/core"
)

Expand Down Expand Up @@ -151,13 +149,15 @@ type HelloResponse struct {
Version string `json:"version"`
CID string `json:"cid"`
Auth *CORE.SuperuserAuth `json:"auth"`
Instances uint16 `json:"instances_num"`
MemoryUsage uint64 `json:"mem_usage"`
SentinelWorks bool `json:"sentinel_works"`
}

type InfoRequest struct {
CID string `json:"cid"`
ID int `json:"id"`
UUID string `json:"UUID"`
UUID string `json:"uuid"`
}

type InfoResponse struct {
Expand Down Expand Up @@ -198,15 +198,6 @@ type ByeRequest struct {

// ////////////////////////////////////////////////////////////////////////////////// //

// GetAuthHeader return API authentication header
func GetAuthHeader(token string) req.Headers {
return req.Headers{
"Authorization": "Bearer " + token,
}
}

// ////////////////////////////////////////////////////////////////////////////////// //

// String returns string representation of client status
func (s ClientState) String() string {
switch s {
Expand Down
6 changes: 3 additions & 3 deletions sync/client/sync_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func PropagateCommand(command API.MasterCommand, id int, uuid string) error {

resp, err := req.Request{
URL: getURL(API.METHOD_PUSH),
Headers: API.GetAuthHeader(CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)),
Auth: req.AuthBearer{CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)},
ContentType: req.CONTENT_TYPE_JSON,
AutoDiscard: true,
Body: &API.PushRequest{
Expand Down Expand Up @@ -66,8 +66,8 @@ func GetReplicationInfo() (*API.ReplicationInfo, error) {
var err error

resp, err := req.Request{
Headers: API.GetAuthHeader(CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)),
URL: getURL(API.METHOD_REPLICATION),
Auth: req.AuthBearer{CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)},
AutoDiscard: true,
}.Get()

Expand Down Expand Up @@ -98,8 +98,8 @@ func GetStatsInfo() (*API.StatsInfo, error) {
var err error

resp, err := req.Request{
Headers: API.GetAuthHeader(CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)),
URL: getURL(API.METHOD_STATS),
Auth: req.AuthBearer{CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)},
AutoDiscard: true,
}.Get()

Expand Down
2 changes: 1 addition & 1 deletion sync/minion/minion.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func getURL(method API.Method) string {
func sendRequest(method API.Method, reqData, respData any) error {
resp, err := req.Request{
URL: getURL(method),
Headers: API.GetAuthHeader(CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)),
Auth: req.AuthBearer{CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)},
ContentType: req.CONTENT_TYPE_JSON,
Body: reqData,
AutoDiscard: true,
Expand Down
2 changes: 1 addition & 1 deletion sync/sentinel/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func getURL(method API.Method) string {
func sendRequest(method API.Method, reqData, respData any) error {
resp, err := req.Request{
URL: getURL(method),
Headers: API.GetAuthHeader(CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)),
Auth: req.AuthBearer{CORE.Config.GetS(CORE.REPLICATION_AUTH_TOKEN)},
ContentType: req.CONTENT_TYPE_JSON,
Body: reqData,
AutoDiscard: true,
Expand Down

0 comments on commit 083ab1c

Please sign in to comment.