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

Small adjusts #18

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ GOCMD ?= go
GOBUILD = $(GOCMD) build
GOTEST = $(GOCMD) test
GOCLEAN = $(GOCMD) clean
GOIMPORTS = goimports
GOFMT = gofmt
LINT = golangci-lint
VULNCHECK = govulncheck
Expand Down Expand Up @@ -32,9 +33,15 @@ test-coverage: check-deps

# Format code
.PHONY: fmt
fmt: check-deps
fmt: check-deps goimports
$(GOFMT) -w .

# Check for goimports
.PHONY: goimports
goimports:
@which $(GOIMPORTS) > /dev/null || (echo "goimports is not installed. Run 'go install golang.org/x/tools/cmd/goimports@latest' to install." && exit 1)
$(GOIMPORTS) -w .

# Lint code
.PHONY: lint
lint: check-deps
Expand Down Expand Up @@ -65,7 +72,7 @@ help:
@echo "Targets:"
@echo " build Compile the project"
@echo " test Run tests"
@echo " fmt Run gofmt on all source files"
@echo " fmt Run goimports and gofmt on all source files"
@echo " lint Run linter"
@echo " security Run security checks"
@echo " ci Run all checks"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_get_request/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"log/slog"

"github.com/opus-domini/fast-shot"
fastshot "github.com/opus-domini/fast-shot"
"github.com/opus-domini/fast-shot/examples/server"
"github.com/opus-domini/fast-shot/examples/server/model"
)
Expand Down
5 changes: 3 additions & 2 deletions examples/custom_headers_and_cookies/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log/slog"
"net/http"

"github.com/opus-domini/fast-shot"
fastshot "github.com/opus-domini/fast-shot"
"github.com/opus-domini/fast-shot/constant/mime"
"github.com/opus-domini/fast-shot/examples/server"
"github.com/opus-domini/fast-shot/examples/server/model"
Expand All @@ -25,7 +25,8 @@ func main() {
resp, err := client.GET("/resources").
Header().AddAccept(mime.JSON).
Send()
// Check if there was an error sending the request.

// Check if there was an error sending the request.
if err != nil {
slog.Error("Error sending the request.", "error", err)
}
Expand Down
5 changes: 3 additions & 2 deletions examples/post_request_with_json/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log/slog"
"time"

"github.com/opus-domini/fast-shot"
fastshot "github.com/opus-domini/fast-shot"
"github.com/opus-domini/fast-shot/examples/server"
"github.com/opus-domini/fast-shot/examples/server/model"
)
Expand All @@ -26,7 +26,8 @@ func main() {
resp, err := client.POST("/users").
Body().AsJSON(newUser).
Send()
// Check if there was an error sending the request.

// Check if there was an error sending the request.
if err != nil {
slog.Error("Error sending the request.", "error", err)
return
Expand Down
3 changes: 2 additions & 1 deletion examples/retry_on_server_error/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log/slog"
"time"

"github.com/opus-domini/fast-shot"
fastshot "github.com/opus-domini/fast-shot"
"github.com/opus-domini/fast-shot/examples/server"
"github.com/opus-domini/fast-shot/examples/server/model"
)
Expand All @@ -22,6 +22,7 @@ func main() {
resp, err := client.GET("/tuples/2").
Retry().SetConstantBackoff(50*time.Millisecond, 10).
Send()

// Check if there was an error sending the request.
if err != nil {
slog.Error("Error sending the request.", "error", err)
Expand Down
4 changes: 3 additions & 1 deletion request_builder_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

func TestRequestContextBuilder(t *testing.T) {
type contextKey string

tests := []struct {
name string
ctx context.Context
Expand All @@ -22,7 +24,7 @@ func TestRequestContextBuilder(t *testing.T) {
},
{
name: "Set context with value",
ctx: context.WithValue(context.Background(), "key", "value"),
ctx: context.WithValue(context.Background(), contextKey("key"), "value"),
},
}

Expand Down
3 changes: 2 additions & 1 deletion request_config_base.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fastshot

import (
"context"
"net/url"
"time"

Expand Down Expand Up @@ -150,7 +151,7 @@ func (c *RetryConfig) SetJitterStrategy(strategy JitterStrategy) {
// NewRequestConfigBase creates a new request configuration.
func newRequestConfigBase(method method.Type, path string) *RequestConfigBase {
return &RequestConfigBase{
ctx: newDefaultContext(nil),
ctx: newDefaultContext(context.Background()),
httpHeader: newDefaultHttpHeader(),
httpCookies: newDefaultHttpCookies(),
method: method,
Expand Down
Loading