Skip to content

Commit

Permalink
refactor: removal of the manyminds/api2go
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbespalov committed Jan 11, 2022
1 parent 87504c9 commit 24cb4f1
Show file tree
Hide file tree
Showing 19 changed files with 2 additions and 1,541 deletions.
41 changes: 2 additions & 39 deletions api/v1/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"net/http"
"net/url"

"github.com/manyminds/api2go/jsonapi"
"github.com/sirupsen/logrus"

v1 "go.k6.io/k6/api/v1"
Expand Down Expand Up @@ -82,42 +81,6 @@ func WithLogger(logger *logrus.Entry) Option {
// CallAPI executes the desired REST API request.
// it's expected that the body and out are the structs that follows the JSON:API
func (c *Client) CallAPI(ctx context.Context, method string, rel *url.URL, body, out interface{}) (err error) {
return c.call(ctx, method, rel, marshaler{
marshal: json.Marshal,
unmarshal: json.Unmarshal,
}, body, out)
}

// Call executes the desired REST API request.
// Deprecated: use instead client.CallAPI
func (c *Client) Call(ctx context.Context, method string, rel *url.URL, body, out interface{}) (err error) {
if c.logger != nil {
c.logger.Warnf(
"client.Call is deprecated and will be removed soon, please migrate to a client.CallAPI for %s request to '%s'",
method,
rel.String(),
)
}

return c.call(ctx, method, rel, marshaler{
marshal: jsonapi.Marshal,
unmarshal: jsonapi.Unmarshal,
}, body, out)
}

// marshaler is the temporary struct that keeps the marshal/unmarshal methods
type marshaler struct {
marshal func(interface{}) ([]byte, error)
unmarshal func([]byte, interface{}) error
}

func (c *Client) call(
ctx context.Context,
method string,
rel *url.URL,
marshaler marshaler,
body, out interface{},
) (err error) {
if c.logger != nil {
c.logger.Debugf("[REST API] Making a %s request to '%s'", method, rel.String())
defer func() {
Expand All @@ -136,7 +99,7 @@ func (c *Client) call(
case string:
bodyData = []byte(val)
default:
bodyData, err = marshaler.marshal(body)
bodyData, err = json.Marshal(body)
if err != nil {
return err
}
Expand Down Expand Up @@ -171,7 +134,7 @@ func (c *Client) call(
}

if out != nil {
return marshaler.unmarshal(data, out)
return json.Unmarshal(data, out)
}
return nil
}
59 changes: 0 additions & 59 deletions api/v1/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ package v1
import (
"fmt"

"github.com/manyminds/api2go/jsonapi"

"go.k6.io/k6/lib"
)

Expand Down Expand Up @@ -84,63 +82,6 @@ func NewGroup(g *lib.Group, parent *Group) *Group {
return group
}

// GetID gets a group ID
// Deprecated: use instead g.ID directly
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (g Group) GetID() string {
return g.ID
}

// SetID sets a group ID
// Deprecated: use instead g.ID directly
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (g *Group) SetID(v string) error {
g.ID = v
return nil
}

// GetReferences returns the slice of jsonapi.References
// Deprecated: use instead g.Groups properties
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (g Group) GetReferences() []jsonapi.Reference {
return []jsonapi.Reference{
{
Type: "groups",
Name: "parent",
Relationship: jsonapi.ToOneRelationship,
},
{
Type: "groups",
Name: "groups",
Relationship: jsonapi.ToManyRelationship,
},
}
}

// GetReferencedIDs returns the slice of jsonapi.ReferenceID
// Deprecated: use instead g.GroupIDs properties
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (g Group) GetReferencedIDs() []jsonapi.ReferenceID {
refs := []jsonapi.ReferenceID{}
if g.Parent != nil {
refs = append(refs, jsonapi.ReferenceID{
ID: g.Parent.GetID(),
Type: "groups",
Name: "parent",
Relationship: jsonapi.ToOneRelationship,
})
}
for _, gp := range g.Groups {
refs = append(refs, jsonapi.ReferenceID{
ID: gp.GetID(),
Type: "groups",
Name: "groups",
Relationship: jsonapi.ToManyRelationship,
})
}
return refs
}

func (g *Group) SetToManyReferenceIDs(name string, ids []string) error {
switch name {
case "groups":
Expand Down
15 changes: 0 additions & 15 deletions api/v1/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,3 @@ func NewMetric(m *stats.Metric, t time.Duration) Metric {
Sample: m.Sink.Format(t),
}
}

// GetID gets a metric ID (name)
// Deprecated: use instead m.Name directly
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (m Metric) GetID() string {
return m.Name
}

// SetID sets a metric ID (name)
// Deprecated: use instead m.Name directly
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (m *Metric) SetID(id string) error {
m.Name = id
return nil
}
14 changes: 0 additions & 14 deletions api/v1/setup_teardown_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ type SetupData struct {
Data interface{} `json:"data" yaml:"data"`
}

// GetName is a dummy method so we can satisfy the jsonapi.EntityNamer interface
// Deprecated: use a constant value instead
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (sd SetupData) GetName() string {
return "setupData"
}

// GetID is a dummy method so we can satisfy the jsonapi.MarshalIdentifier interface
// Deprecated: use a constant value instead
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (sd SetupData) GetID() string {
return "default"
}

func handleSetupDataOutput(rw http.ResponseWriter, setupData json.RawMessage) {
rw.Header().Set("Content-Type", "application/json")
var err error
Expand Down
19 changes: 0 additions & 19 deletions api/v1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,3 @@ func NewStatus(engine *core.Engine) Status {
Tainted: engine.IsTainted(),
}
}

// GetName gets the entity name, implementation of the interface for the jsonapi
// Deprecated: use a constant value instead
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (s Status) GetName() string {
return "status"
}

// GetID gets a status ID (there is no real ID for the status)
// Deprecated: use a constant value instead
// This method will be removed with the one of the PRs of (https://github.com/grafana/k6/issues/911)
func (s Status) GetID() string {
return "default"
}

// SetID do nothing, required by the jsonapi interface
func (s Status) SetID(id string) error {
return nil
}
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/klauspost/compress v1.13.6
github.com/mailru/easyjson v0.7.7
github.com/manyminds/api2go v0.0.0-20180125085803-95be7bd0455e
github.com/mattn/go-colorable v0.1.8
github.com/mattn/go-isatty v0.0.13
github.com/mccutchen/go-httpbin v1.1.2-0.20190116014521-c5cb2f4802fa
Expand Down Expand Up @@ -46,7 +45,6 @@ require (
github.com/andybalholm/cascadia v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -56,5 +54,4 @@ require (
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect
golang.org/x/text v0.3.7-0.20210503195748-5c7c50ebbd4f // indirect
google.golang.org/genproto v0.0.0-20200903010400-9bfcb5116336 // indirect
gopkg.in/guregu/null.v2 v2.1.2 // indirect
)
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGE
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 h1:Uc+IZ7gYqAf/rSGFplbWBSHaGolEQlNLgMgSE3ccnIQ=
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813/go.mod h1:P+oSoE9yhSRvsmYyZsshflcR6ePWYLql6UU1amW13IM=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
Expand Down Expand Up @@ -177,8 +175,6 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/manyminds/api2go v0.0.0-20180125085803-95be7bd0455e h1:Jg9dDZCJYqtv9GHQ34yDBFgEJLl4Hi4VEkKUyzHXCV8=
github.com/manyminds/api2go v0.0.0-20180125085803-95be7bd0455e/go.mod h1:Z60vy0EZVSu0bOugCHdcN5ZxFMKSpjRgsnh0XKPFqqk=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down Expand Up @@ -466,8 +462,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/guregu/null.v2 v2.1.2 h1:YOuepWdYqGnrenzPyMi+ybCjeDzjdazynbwsXXOk4i8=
gopkg.in/guregu/null.v2 v2.1.2/go.mod h1:XORrx8tyS5ZDcyUboCIxQtta/Aujk/6pfWrn9Xe33mU=
gopkg.in/guregu/null.v3 v3.3.0 h1:8j3ggqq+NgKt/O7mbFVUFKUMWN+l1AmT5jQmJ6nPh2c=
gopkg.in/guregu/null.v3 v3.3.0/go.mod h1:E4tX2Qe3h7QdL+uZ3a0vqvYwKQsRSQKM5V4YltdgH9Y=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand Down
28 changes: 0 additions & 28 deletions vendor/github.com/gedex/inflector/CakePHP_LICENSE.txt

This file was deleted.

29 changes: 0 additions & 29 deletions vendor/github.com/gedex/inflector/LICENSE.md

This file was deleted.

25 changes: 0 additions & 25 deletions vendor/github.com/gedex/inflector/README.md

This file was deleted.

Loading

0 comments on commit 24cb4f1

Please sign in to comment.