Skip to content

Change the required Go version to v1.21 #7

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

Open
wants to merge 2 commits into
base: master
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

## Installation

Requires Go 1.17+.
Requires Go 1.21+.

```go get github.com/seven-io/go-client/sms77api```

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/seven-io/go-client

go 1.17
go 1.21

require github.com/stretchr/testify v1.10.0

Expand Down
2 changes: 1 addition & 1 deletion sms77api/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (api *ContactsResource) ReadJsonContext(ctx context.Context, p ContactsRead
return
}

json.Unmarshal([]byte(s), &a)
e = json.Unmarshal([]byte(s), &a)

return
}
Expand Down
7 changes: 5 additions & 2 deletions sms77api/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package sms77api

import (
"fmt"
a "github.com/stretchr/testify/assert"
"slices"
"strings"
"testing"

a "github.com/stretchr/testify/assert"
)

var createdId uint64
Expand Down Expand Up @@ -46,7 +48,8 @@ func getDeleteParams() ContactsDeleteParams {
}

func isValidCode(needle ContactsWriteCode) bool {
return inArray(needle, [...]ContactsWriteCode{ContactsWriteCodeUnchanged, ContactsWriteCodeChanged})
validCodes := []ContactsWriteCode{ContactsWriteCodeUnchanged, ContactsWriteCodeChanged}
return slices.Contains(validCodes, needle)
}

func prepareEdit() (Contact, string) {
Expand Down
12 changes: 6 additions & 6 deletions sms77api/sms77api.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,23 @@ func (api *Sms77API) request(ctx context.Context, endpoint string, method string
data = map[string]interface{}{}
}
data, _ = json.Marshal(&data)
json.Unmarshal(data.([]byte), &data)
_ = json.Unmarshal(data.([]byte), &data)

req, err := initClient()
if err != nil {
return "", fmt.Errorf("could not execute request! #1 (%s)", err.Error())
return "", fmt.Errorf("could not execute request! #1 (%w)", err)
}

res, err := api.client.Do(req)
if err != nil {
return "", fmt.Errorf("could not execute request! #2 (%s)", err.Error())
return "", fmt.Errorf("could not execute request! #2 (%w)", err)
}

defer res.Body.Close()

body, err := io.ReadAll(res.Body)
if err != nil {
return "", fmt.Errorf("could not execute request! #3 (%s)", err.Error())
return "", fmt.Errorf("could not execute request! #3 (%w)", err)
}

str := strings.TrimSpace(string(body))
Expand All @@ -226,8 +226,8 @@ func (api *Sms77API) request(ctx context.Context, endpoint string, method string
length := len(str)

if 2 == length || 3 == length {
code, msg := pickMapByKey(str, StatusCodes)
if nil != code {
code := StatusCode(str)
if msg, ok := StatusCodes[code]; ok {
return "", fmt.Errorf("%s: %s", code, msg)
}
}
Expand Down
26 changes: 0 additions & 26 deletions sms77api/util.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@
package sms77api

import (
"reflect"
"strconv"
)

func pickMapByKey(needle interface{}, haystack interface{}) (interface{}, interface{}) {
mapIter := reflect.ValueOf(haystack).MapRange()

for mapIter.Next() {
if needle == mapIter.Key() {
return needle, mapIter.Value()
}
}

return nil, nil
}

func inArray(needle interface{}, haystack interface{}) bool {
slice := reflect.ValueOf(haystack)
c := slice.Len()

for i := 0; i < c; i++ {
if needle == slice.Index(i).Interface() {
return true
}
}

return false
}

func toUint(id string, bitSize int) uint64 {
n, err := strconv.ParseUint(id, 10, bitSize)

Expand Down