Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
appver
Browse files Browse the repository at this point in the history
  • Loading branch information
melekhine committed Aug 8, 2023
1 parent 95fc8d6 commit 7822600
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {
// newRequest creates new http request to RSP.
func newRequest(ctx context.Context, method, link, apiToken string, payload []byte) (*http.Request, error) {
req, err := http.NewRequestWithContext(ctx, method, link, bytes.NewBuffer(payload))
req.Header.Set("User-Agent", userAgent+"/"+Version)
req.Header.Set("User-Agent", version())
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", "Bearer "+apiToken)
Expand Down
17 changes: 16 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package qiwi

import "fmt"

// AppVersion for version string of main application version

Check failure on line 5 in version.go

View workflow job for this annotation

GitHub Actions / Lint

Comment should end in a period (godot)
var AppVersion string

const (
// Version string.
Version string = "0.3"
Version string = "1.0.0"
userAgent string = "Sendtips-QIWI-Go" // UserAgent name
)

func version() (s string) {
s = fmt.Sprintf("%s/%s", userAgent, Version)

Check failure on line 16 in version.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofmt`-ed with `-s` (gofmt)
if AppVersion != "" {
s = fmt.Sprintf("%s (%s)", AppVersion, s)
}

return s
}
22 changes: 22 additions & 0 deletions version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package qiwi

import (
"fmt"
"testing"
)

func TestVersion(t *testing.T) {
s := fmt.Sprintf("%s/%s", userAgent, Version)

Check failure on line 10 in version_test.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofmt`-ed with `-s` (gofmt)
if s != version() {
t.Error("Version string is invalid")
}

AppVersion = "somever/1.0"
s = fmt.Sprintf("%s (%s/%s)", AppVersion, userAgent, Version)

if s != version() {
t.Error("Version string is invalid")
}

Check failure on line 21 in version_test.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)
}

0 comments on commit 7822600

Please sign in to comment.