Skip to content

Commit

Permalink
Prefer constants
Browse files Browse the repository at this point in the history
No description

---

Pull Request resolved: #184
commit_hash:14d46b3c6cb785690b84f809c4d2201a66e53e59
  • Loading branch information
kamushadenes authored and robot-piglet committed Jan 27, 2025
1 parent 93c257d commit 68852ea
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions pkg/instanceutil/metadata_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func GetIdentityDocument() (string, error) {

func makeGoogleMetadataRequest(param GoogleCEMetaDataParam, recursive bool) (*http.Request, error) {
url := fmt.Sprintf("http://%v/computeMetadata/v1/instance/%v?recursive=%v", InstanceMetadataAddr, param, recursive)
request, err := http.NewRequest("GET", url, nil)
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -91,7 +91,7 @@ const (

func GetAmazonEC2MetaData(param AmazonEC2MetaDataParam) (string, error) {
url := fmt.Sprintf("http://%v/latest/meta-data/%v", InstanceMetadataAddr, param)
request, err := http.NewRequest("GET", url, nil)
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", xerrors.Errorf("cannot get metadata: %w", err)
}
Expand All @@ -101,7 +101,7 @@ func GetAmazonEC2MetaData(param AmazonEC2MetaDataParam) (string, error) {
func GetAmazonEC2UserData(out interface{}) error {
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-add-user-data.html
url := fmt.Sprintf("http://%v/latest/user-data", InstanceMetadataAddr)
request, err := http.NewRequest("GET", url, nil)
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return xerrors.Errorf("cannot make request for user data: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/coralogix/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func SubmitLogs(data []HTTPLogItem, domain, token string) error {
}
body := bytes.NewReader(payloadBytes)

req, err := http.NewRequest("POST", fmt.Sprintf("https://ingress.%s/logs/v1/singles", domain), body)
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("https://ingress.%s/logs/v1/singles", domain), body)
if err != nil {
return xerrors.Errorf("unable to make request: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/providers/elastic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package elastic
import (
"fmt"
"io/ioutil"
"net"
"reflect"
"unsafe"

Expand All @@ -29,7 +30,7 @@ func openSearchResolveHosts(clusterID string) ([]string, error) {
result := make([]string, 0)
for _, currHost := range hosts {
if currHost.Type == "OPENSEARCH" {
result = append(result, fmt.Sprintf("https://%s:%d", currHost.Name, 9200))
result = append(result, fmt.Sprintf("https://%s", net.JoinHostPort(currHost.Name, "9200")))
}
}
return result, nil
Expand All @@ -43,7 +44,7 @@ func elasticSearchResolveHosts(clusterID string) ([]string, error) {
result := make([]string, 0)
for _, currHost := range hosts {
if currHost.Type == "DATA_NODE" {
result = append(result, fmt.Sprintf("https://%s:%d", currHost.Name, 9200))
result = append(result, fmt.Sprintf("https://%s", net.JoinHostPort(currHost.Name, "9200")))
}
}
return result, nil
Expand Down Expand Up @@ -78,7 +79,7 @@ func ConfigFromDestination(logger log.Logger, cfg *ElasticSearchDestination, ser
}

if cfg.ClusterID == "" {
var protocol = "http"
protocol := "http"
if cfg.SSLEnabled {
protocol = "https"
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/providers/elastic/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ func (s *Sink) applyIndexDump(item abstract.ChangeItem) error {
if err != nil {
return xerrors.Errorf("unable to check if index %q exists: %w", indexName, err)
}
if response.StatusCode == 200 {
if response.StatusCode == http.StatusOK {
s.existsIndexesMutex.Lock()
defer s.existsIndexesMutex.Unlock()
s.existsIndexes.Add(tableID)
return nil
}
if response.StatusCode != 404 {
if response.StatusCode != http.StatusNotFound {
return xerrors.Errorf("wrong status code when checking index %q: %s", indexName, response.String())
}

Expand Down Expand Up @@ -215,10 +215,10 @@ func sanitizeKeysInMap(in map[string]interface{}) []map[string]interface{} {

func sanitizeMapKey(in string) string {
runes := []rune(in)
var outStringLen = 0
outStringLen := 0

var startCopyStr = 0
var isEmptyCopyStr = true
startCopyStr := 0
isEmptyCopyStr := true
for i := 0; i <= len(runes); i++ {
if i == len(runes) || runes[i] == '.' {
if !isEmptyCopyStr {
Expand Down Expand Up @@ -300,7 +300,7 @@ func (s *Sink) pushBatch(changeItems []abstract.ChangeItem) error {
if len(changeItems) == 0 {
return nil
}
var indexResult = make(chan error)
indexResult := make(chan error)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/serverutil/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func PingFunc(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "Application/json")
res, _ := json.Marshal(map[string]interface{}{"ping": "pong", "ts": time.Now()})
if _, err := w.Write(res); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/transformer/registry/lambda/lambda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestLambdaTransformer(t *testing.T) {
}
js, err := json.Marshal(data)
require.NoError(t, err)
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(js)
require.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion tests/tcrecipes/azure/azurite.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azure
import (
"context"
"fmt"
"net"

"github.com/docker/go-connections/nat"
"github.com/testcontainers/testcontainers-go"
Expand Down Expand Up @@ -45,7 +46,7 @@ func (c *AzuriteContainer) ServiceURL(ctx context.Context, srv Service) (string,
return "", err
}

return fmt.Sprintf("http://%s:%d", hostname, mappedPort.Int()), nil
return fmt.Sprintf("http://%s", net.JoinHostPort(hostname, mappedPort.Port())), nil
}

func (c *AzuriteContainer) MustServiceURL(ctx context.Context, srv Service) string {
Expand Down
4 changes: 2 additions & 2 deletions tests/tcrecipes/azure/eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package azure
import (
"context"
"fmt"
"net"
"os"
"time"

Expand Down Expand Up @@ -31,7 +32,7 @@ func (c *EventHubContainer) ServiceURL(ctx context.Context) (string, error) {
return "", fmt.Errorf("unable to get mapped port: %s: %w", EventHubPort, err)
}

return fmt.Sprintf("http://%s:%d", hostname, mappedPort.Int()), nil
return fmt.Sprintf("http://%s", net.JoinHostPort(hostname, mappedPort.Port())), nil
}

func (c *EventHubContainer) MustServiceURL(ctx context.Context) string {
Expand All @@ -45,7 +46,6 @@ func (c *EventHubContainer) MustServiceURL(ctx context.Context) string {

// Run creates an instance of the Eventhub container type
func RunEventHub(ctx context.Context, img string, blobAddress string, opts ...testcontainers.ContainerCustomizer) (*EventHubContainer, error) {

req := testcontainers.ContainerRequest{
Image: img,
WaitingFor: wait.ForListeningPort(EventHubPort).WithStartupTimeout(3 * time.Second),
Expand Down

0 comments on commit 68852ea

Please sign in to comment.