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

Use FastEdge SDK func for version header #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.23.3

require (
github.com/G-Core/FastEdge-client-sdk-go v0.3.0
github.com/G-Core/FastEdge-client-sdk-go v0.3.1
github.com/alecthomas/assert v1.0.0
github.com/dromara/carbon/v2 v2.5.2
github.com/dustin/go-humanize v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/G-Core/FastEdge-client-sdk-go v0.3.0 h1:+7opQ/x6VCai8ggHKVkzi/3t0o+wD4CfPilzZUEqdLU=
github.com/G-Core/FastEdge-client-sdk-go v0.3.0/go.mod h1:ggyUVhy8/OCMBY4nbm7n9qDoPioROCk4vHhDJq9w7qE=
github.com/G-Core/FastEdge-client-sdk-go v0.3.1 h1:qtBjlw0tGxztQ6PSqwGJxfo0BZ1sudrm5ECwtIXEdxc=
github.com/G-Core/FastEdge-client-sdk-go v0.3.1/go.mod h1:ggyUVhy8/OCMBY4nbm7n9qDoPioROCk4vHhDJq9w7qE=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/alecthomas/assert v1.0.0 h1:3XmGh/PSuLzDbK3W2gUbRXwgW5lqPkuqvRgeQ30FI5o=
github.com/alecthomas/assert v1.0.0/go.mod h1:va/d2JC+M7F6s+80kl/R3G7FUiW6JzUO+hPhLyJ36ZY=
Expand Down
23 changes: 1 addition & 22 deletions internal/commands/fastedge/fastedge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ import (
"encoding/json"
"fmt"
"net/http"
"runtime/debug"
"strings"

"github.com/dromara/carbon/v2"
"github.com/spf13/cobra"

sdk "github.com/G-Core/FastEdge-client-sdk-go"
)

const (
versionHeaderName = "Fastedge-Sdk-Version"
SDKpackage = "github.com/G-Core/FastEdge-client-sdk-go"
)

var client *sdk.ClientWithResponses

// top-level FastEdge command
Expand All @@ -38,7 +31,7 @@ func Commands(baseUrl string, authFunc func(ctx context.Context, req *http.Reque
client, err = sdk.NewClientWithResponses(
url,
sdk.WithRequestEditorFn(authFunc),
sdk.WithRequestEditorFn(addSDKversionHeader),
sdk.WithRequestEditorFn(sdk.AddVersionHeader),
)
if err != nil {
return fmt.Errorf("cannot init SDK: %w", err)
Expand All @@ -63,20 +56,6 @@ func newPointer[T any](val T) *T {
return &val
}

func addSDKversionHeader(ctx context.Context, req *http.Request) error {
bi, ok := debug.ReadBuildInfo()
if ok {
for _, dep := range bi.Deps {
if dep.Path == SDKpackage {
ver := strings.SplitN(dep.Version, "-", 2) // drop revision info
req.Header.Set(versionHeaderName, ver[0])
return nil
}
}
}
return nil
}

type errResponse struct {
Error string `json:"error"`
}
Expand Down
Loading