bump github.com/tribalwarshelp/shared

This commit is contained in:
Dawid Wysokiński 2021-05-02 16:07:54 +02:00
parent 622eeb3ee8
commit a0ac50f7fe
11 changed files with 57 additions and 60 deletions

View File

@ -2,12 +2,12 @@ package main
import (
"fmt"
"github.com/tribalwarshelp/shared/tw/twmodel"
"log"
"os"
"time"
"github.com/tribalwarshelp/golang-sdk/sdk"
"github.com/tribalwarshelp/shared/models"
)
func init() {
@ -17,13 +17,13 @@ func init() {
func main() {
api := sdk.New("https://api.tribalwarshelp.com/graphql")
version, err := api.Version.Read(models.VersionCodePL)
version, err := api.Version.Read(twmodel.VersionCodePL)
if err != nil {
log.Fatal(err)
}
log.Println(version.Name, version.Code, version.Host, version.Timezone)
versionList, err := api.Version.Browse(0, 0, []string{}, &models.VersionFilter{
versionList, err := api.Version.Browse(0, 0, []string{}, &twmodel.VersionFilter{
HostMATCH: "plemiona%",
})
if err != nil {
@ -57,7 +57,7 @@ func main() {
10,
0,
[]string{"rank ASC"},
&models.PlayerFilter{},
&twmodel.PlayerFilter{},
&sdk.PlayerInclude{
Tribe: true,
})
@ -77,7 +77,7 @@ func main() {
}
log.Println(tribe.ID, tribe.Name, tribe.Tag, tribe.RankAtt, tribe.RankDef)
tribeList, err := api.Tribe.Browse("pl151", 10, 0, []string{}, &models.TribeFilter{
tribeList, err := api.Tribe.Browse("pl151", 10, 0, []string{}, &twmodel.TribeFilter{
TagIEQ: ":.+.:",
})
if err != nil {
@ -108,7 +108,7 @@ func main() {
10,
0,
[]string{"id ASC"},
&models.VillageFilter{
&twmodel.VillageFilter{
PlayerID: []int{699270453},
}, &sdk.VillageInclude{
Player: true,
@ -135,7 +135,7 @@ func main() {
100,
0,
[]string{},
&models.EnnoblementFilter{
&twmodel.EnnoblementFilter{
EnnobledAtGTE: time.Now().Add(-1 * time.Hour),
},
&sdk.EnnoblementInclude{

3
go.mod
View File

@ -3,7 +3,8 @@ module github.com/tribalwarshelp/golang-sdk
go 1.16
require (
github.com/Kichiyaki/goutil v0.0.0-20210502135617-7868852b90cc
github.com/Kichiyaki/gqlgen-client v0.0.0-20200604145848-274796c104f4
github.com/pkg/errors v0.9.1
github.com/tribalwarshelp/shared v0.0.0-20210423190057-03d8445d35dc
github.com/tribalwarshelp/shared v0.0.0-20210502140609-e137bd656c94
)

12
go.sum
View File

@ -1,5 +1,10 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Kichiyaki/go-php-serialize v0.0.0-20200601110855-47b6982acf83/go.mod h1:+iGkf5HfOVeRVd9K7qQDucIl+/Kt3MyenMa90b/O/c4=
github.com/Kichiyaki/gopgutil/v10 v10.0.0-20210502140321-8b7f2b75ad67 h1:bg+jweFLCKC5X2tKck8IXmAbkOW26hxibg9Od1+eCKA=
github.com/Kichiyaki/gopgutil/v10 v10.0.0-20210502140321-8b7f2b75ad67/go.mod h1:Q3QaLlZY3/FcqwmTpdYqoAAGCmPYzrL7hCL7e5kzmjQ=
github.com/Kichiyaki/goutil v0.0.0-20210502135617-7868852b90cc h1:055XPMujAD91cCD8KhbXgpjekwK0AOLEPN54n6A7308=
github.com/Kichiyaki/goutil v0.0.0-20210502135617-7868852b90cc/go.mod h1:+HhI932Xb0xrCodNcCv5GPiCjLYhDxWhCtlEqMIJhB4=
github.com/Kichiyaki/gqlgen-client v0.0.0-20200604145848-274796c104f4 h1:QiOarkkKHdFYI+0m6F1H3rRzP6DqJsKJVLirGXEHGSU=
github.com/Kichiyaki/gqlgen-client v0.0.0-20200604145848-274796c104f4/go.mod h1:weCVl47ZANyeX60sdsSl0bWHf8HWXyVFmlGHHCR/i5M=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@ -61,9 +66,7 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@ -71,8 +74,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
github.com/tribalwarshelp/shared v0.0.0-20210423190057-03d8445d35dc h1:giWPsD/6WTOrQl9KT5AXrrf3KLkHSGuNpWa2CyyaM6w=
github.com/tribalwarshelp/shared v0.0.0-20210423190057-03d8445d35dc/go.mod h1:CDQvesBYmSyGDl5X37xfa+ub55ZbikrHDuIZ4AcfM8I=
github.com/tribalwarshelp/shared v0.0.0-20210502140609-e137bd656c94 h1:tQysqj1zlVBLFiRqVYRlRd4hPg5EBKGwYav7+gjxQMo=
github.com/tribalwarshelp/shared v0.0.0-20210502140609-e137bd656c94/go.mod h1:NDNw8pZ/lbNaORVwGWl22+Czf4pwtwXELR2ExeUn0q0=
github.com/vmihailenco/bufpool v0.1.11 h1:gOq2WmBrq0i2yW5QJ16ykccQ4wH9UyEsgLm6czKAd94=
github.com/vmihailenco/bufpool v0.1.11/go.mod h1:AFf/MOy3l2CFTKbxwt0mp2MwnqjNEs5H/UxrkA5jxTQ=
github.com/vmihailenco/msgpack/v5 v5.3.0/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
@ -124,7 +127,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -2,10 +2,10 @@ package sdk
import (
"fmt"
"github.com/tribalwarshelp/shared/tw/twmodel"
"github.com/Kichiyaki/gqlgen-client/client"
"github.com/pkg/errors"
"github.com/tribalwarshelp/shared/models"
)
type Ennoblement struct {
@ -49,15 +49,15 @@ func (incl EnnoblementInclude) String() string {
}
type EnnoblementList struct {
Items []*models.Ennoblement `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
Items []*twmodel.Ennoblement `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
}
func (en *Ennoblement) Browse(server string,
limit,
offset int,
sort []string,
filter *models.EnnoblementFilter,
filter *twmodel.EnnoblementFilter,
include *EnnoblementInclude) (*EnnoblementList, error) {
if server == "" {
return nil, ErrServerNameIsEmpty

View File

@ -1,7 +0,0 @@
package sdk
import "strings"
func minifyString(str string) string {
return strings.Join(strings.Fields(str), " ")
}

View File

@ -2,10 +2,10 @@ package sdk
import (
"fmt"
"github.com/tribalwarshelp/shared/tw/twmodel"
"github.com/Kichiyaki/gqlgen-client/client"
"github.com/pkg/errors"
"github.com/tribalwarshelp/shared/models"
)
type Player struct {
@ -28,7 +28,7 @@ func (incl PlayerInclude) String() string {
return i
}
func (p *Player) Read(server string, id int, include *PlayerInclude) (*models.Player, error) {
func (p *Player) Read(server string, id int, include *PlayerInclude) (*twmodel.Player, error) {
if server == "" {
return nil, ErrServerNameIsEmpty
}
@ -36,7 +36,7 @@ func (p *Player) Read(server string, id int, include *PlayerInclude) (*models.Pl
include = &PlayerInclude{}
}
resp := struct {
Player models.Player `json:"player" gqlgen:"player"`
Player twmodel.Player `json:"player" gqlgen:"player"`
}{}
query := fmt.Sprintf(`
@ -55,21 +55,21 @@ func (p *Player) Read(server string, id int, include *PlayerInclude) (*models.Pl
}
type PlayerList struct {
Items []*models.Player `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
Items []*twmodel.Player `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
}
func (p *Player) Browse(server string,
limit,
offset int,
sort []string,
filter *models.PlayerFilter,
filter *twmodel.PlayerFilter,
include *PlayerInclude) (*PlayerList, error) {
if server == "" {
return nil, ErrServerNameIsEmpty
}
if filter == nil {
filter = &models.PlayerFilter{}
filter = &twmodel.PlayerFilter{}
}
if include == nil {
include = &PlayerInclude{}

View File

@ -2,6 +2,7 @@ package sdk
import (
"fmt"
"github.com/Kichiyaki/goutil/strutil"
"io/ioutil"
"net/http"
"time"
@ -109,7 +110,7 @@ func New(url string) *SDK {
}
func (sdk *SDK) Post(query string, response interface{}, options ...client.Option) error {
return sdk.client.Post(minifyString(query), response, options...)
return sdk.client.Post(strutil.Minify(query, " "), response, options...)
}
func (sdk *SDK) doRequest(w http.ResponseWriter, r *http.Request) {

View File

@ -2,10 +2,10 @@ package sdk
import (
"fmt"
"github.com/tribalwarshelp/shared/tw/twmodel"
"github.com/Kichiyaki/gqlgen-client/client"
"github.com/pkg/errors"
"github.com/tribalwarshelp/shared/models"
)
type Server struct {
@ -28,12 +28,12 @@ func (incl ServerInclude) String() string {
return i
}
func (s *Server) Read(key string, incl *ServerInclude) (*models.Server, error) {
func (s *Server) Read(key string, incl *ServerInclude) (*twmodel.Server, error) {
if incl == nil {
incl = &ServerInclude{}
}
resp := struct {
Server models.Server `json:"server" gqlgen:"server"`
Server twmodel.Server `json:"server" gqlgen:"server"`
}{}
query := fmt.Sprintf(`
query server($key: String!) {
@ -58,20 +58,20 @@ func (s *Server) Read(key string, incl *ServerInclude) (*models.Server, error) {
}
type ServerList struct {
Items []*models.Server `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
Items []*twmodel.Server `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
}
func (s *Server) Browse(limit,
offset int,
sort []string,
filter *models.ServerFilter,
filter *twmodel.ServerFilter,
incl *ServerInclude) (*ServerList, error) {
if incl == nil {
incl = &ServerInclude{}
}
if filter == nil {
filter = &models.ServerFilter{}
filter = &twmodel.ServerFilter{}
}
resp := struct {
Servers ServerList `json:"servers" gqlgen:"servers"`

View File

@ -2,19 +2,19 @@ package sdk
import (
"fmt"
"github.com/tribalwarshelp/shared/tw/twmodel"
"github.com/Kichiyaki/gqlgen-client/client"
"github.com/pkg/errors"
"github.com/tribalwarshelp/shared/models"
)
type Tribe struct {
sdk *SDK
}
func (t *Tribe) Read(server string, id int) (*models.Tribe, error) {
func (t *Tribe) Read(server string, id int) (*twmodel.Tribe, error) {
resp := struct {
Tribe models.Tribe `json:"tribe" gqlgen:"tribe"`
Tribe twmodel.Tribe `json:"tribe" gqlgen:"tribe"`
}{}
query := fmt.Sprintf(`
query tribe($server: String!, $id: Int!) {
@ -31,17 +31,17 @@ func (t *Tribe) Read(server string, id int) (*models.Tribe, error) {
}
type TribeList struct {
Items []*models.Tribe `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
Items []*twmodel.Tribe `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
}
func (t *Tribe) Browse(server string,
limit,
offset int,
sort []string,
filter *models.TribeFilter) (*TribeList, error) {
filter *twmodel.TribeFilter) (*TribeList, error) {
if filter == nil {
filter = &models.TribeFilter{}
filter = &twmodel.TribeFilter{}
}
resp := struct {
Tribes TribeList `json:"tribes" gqlgen:"tribes"`

View File

@ -2,19 +2,19 @@ package sdk
import (
"fmt"
"github.com/tribalwarshelp/shared/tw/twmodel"
"github.com/Kichiyaki/gqlgen-client/client"
"github.com/pkg/errors"
"github.com/tribalwarshelp/shared/models"
)
type Version struct {
sdk *SDK
}
func (v *Version) Read(code models.VersionCode) (*models.Version, error) {
func (v *Version) Read(code twmodel.VersionCode) (*twmodel.Version, error) {
resp := struct {
Version models.Version `json:"version" gqlgen:"version"`
Version twmodel.Version `json:"version" gqlgen:"version"`
}{}
query := fmt.Sprintf(`
query version($code: VersionCode!) {
@ -31,16 +31,16 @@ func (v *Version) Read(code models.VersionCode) (*models.Version, error) {
}
type VersionList struct {
Items []*models.Version `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
Items []*twmodel.Version `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
}
func (v *Version) Browse(limit,
offset int,
sort []string,
filter *models.VersionFilter) (*VersionList, error) {
filter *twmodel.VersionFilter) (*VersionList, error) {
if filter == nil {
filter = &models.VersionFilter{}
filter = &twmodel.VersionFilter{}
}
resp := struct {
Versions VersionList `json:"versions" gqlgen:"versions"`

View File

@ -2,10 +2,10 @@ package sdk
import (
"fmt"
"github.com/tribalwarshelp/shared/tw/twmodel"
"github.com/Kichiyaki/gqlgen-client/client"
"github.com/pkg/errors"
"github.com/tribalwarshelp/shared/models"
)
type Village struct {
@ -30,7 +30,7 @@ func (incl VillageInclude) String() string {
return i
}
func (v *Village) Read(server string, id int, include *VillageInclude) (*models.Village, error) {
func (v *Village) Read(server string, id int, include *VillageInclude) (*twmodel.Village, error) {
if server == "" {
return nil, ErrServerNameIsEmpty
}
@ -38,7 +38,7 @@ func (v *Village) Read(server string, id int, include *VillageInclude) (*models.
include = &VillageInclude{}
}
resp := struct {
Village models.Village `json:"village" gqlgen:"village"`
Village twmodel.Village `json:"village" gqlgen:"village"`
}{}
query := fmt.Sprintf(`
@ -57,21 +57,21 @@ func (v *Village) Read(server string, id int, include *VillageInclude) (*models.
}
type VillageList struct {
Items []*models.Village `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
Items []*twmodel.Village `json:"items" gqlgen:"items"`
Total int `json:"total" gqlgen:"total"`
}
func (v *Village) Browse(server string,
limit,
offset int,
sort []string,
filter *models.VillageFilter,
filter *twmodel.VillageFilter,
include *VillageInclude) (*VillageList, error) {
if server == "" {
return nil, ErrServerNameIsEmpty
}
if filter == nil {
filter = &models.VillageFilter{}
filter = &twmodel.VillageFilter{}
}
if include == nil {
include = &VillageInclude{}