Skip to content

Commit

Permalink
no more Json suffix
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Rash <[email protected]>
  • Loading branch information
jordan-rash committed Jan 7, 2025
1 parent a64507b commit 724e06d
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 278 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tasks:
gen-schema-api:
dir: api
cmds:
- go-jsonschema
- go-jsonschema --struct-name-from-title
--package api --tags json
--schema-output=io.nats.nex.v2.agent_register_request=go/agent.go
--schema-output=io.nats.nex.v2.agent_register_response=go/agent.go
Expand Down
52 changes: 26 additions & 26 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func NewControlApiClient(nc *nats.Conn, logger *slog.Logger) (*ControlAPIClient,
}, nil
}

func (c *ControlAPIClient) Auction(namespace string, tags map[string]string) ([]*nodegen.AuctionResponseJson, error) {
resp := []*nodegen.AuctionResponseJson{}
func (c *ControlAPIClient) Auction(namespace string, tags map[string]string) ([]*nodegen.AuctionResponse, error) {
resp := []*nodegen.AuctionResponse{}
auctionRespInbox := nats.NewInbox()

s, err := c.nc.Subscribe(auctionRespInbox, func(m *nats.Msg) {
envelope := new(models.Envelope[nodegen.AuctionResponseJson])
envelope := new(models.Envelope[nodegen.AuctionResponse])
err := json.Unmarshal(m.Data, envelope)
if err != nil {
c.logger.Error("failed to unmarshal auction response", slog.Any("err", err), slog.String("data", string(m.Data)))
Expand All @@ -48,9 +48,9 @@ func (c *ControlAPIClient) Auction(namespace string, tags map[string]string) ([]
}
}()

req := nodegen.AuctionRequestJson{
req := nodegen.AuctionRequest{
AuctionId: nuid.New().Next(),
Tags: nodegen.AuctionRequestJsonTags{
Tags: nodegen.AuctionRequestTags{
Tags: tags,
},
}
Expand All @@ -68,12 +68,12 @@ func (c *ControlAPIClient) Auction(namespace string, tags map[string]string) ([]
return resp, nil
}

func (c *ControlAPIClient) Ping() ([]*nodegen.NodePingResponseJson, error) {
resp := []*nodegen.NodePingResponseJson{}
func (c *ControlAPIClient) Ping() ([]*nodegen.NodePingResponse, error) {
resp := []*nodegen.NodePingResponse{}
pingRespInbox := nats.NewInbox()

s, err := c.nc.Subscribe(pingRespInbox, func(m *nats.Msg) {
envelope := new(models.Envelope[nodegen.NodePingResponseJson])
envelope := new(models.Envelope[nodegen.NodePingResponse])
err := json.Unmarshal(m.Data, envelope)
if err != nil {
c.logger.Debug("failed to unmarshal ping response", slog.Any("err", err), slog.String("data", string(m.Data)))
Expand All @@ -100,13 +100,13 @@ func (c *ControlAPIClient) Ping() ([]*nodegen.NodePingResponseJson, error) {
return resp, nil
}

func (c *ControlAPIClient) DirectPing(nodeId string) (*nodegen.NodePingResponseJson, error) {
func (c *ControlAPIClient) DirectPing(nodeId string) (*nodegen.NodePingResponse, error) {
msg, err := c.nc.Request(models.DirectPingSubject(nodeId), nil, DefaultRequestTimeout)
if err != nil {
return nil, err
}

envelope := new(models.Envelope[nodegen.NodePingResponseJson])
envelope := new(models.Envelope[nodegen.NodePingResponse])
err = json.Unmarshal(msg.Data, envelope)
if err != nil {
return nil, err
Expand All @@ -115,13 +115,13 @@ func (c *ControlAPIClient) DirectPing(nodeId string) (*nodegen.NodePingResponseJ
return &envelope.Data, nil
}

func (c *ControlAPIClient) FindWorkload(namespace, workloadId string) (*nodegen.WorkloadPingResponseJson, error) {
func (c *ControlAPIClient) FindWorkload(namespace, workloadId string) (*nodegen.WorkloadPingResponse, error) {
msg, err := c.nc.Request(models.WorkloadPingRequestSubject(namespace, workloadId), nil, DefaultRequestTimeout)
if err != nil {
return nil, err
}

envelope := new(models.Envelope[nodegen.WorkloadPingResponseJson])
envelope := new(models.Envelope[nodegen.WorkloadPingResponse])
err = json.Unmarshal(msg.Data, envelope)
if err != nil {
return nil, err
Expand Down Expand Up @@ -162,7 +162,7 @@ func (c *ControlAPIClient) ListWorkloads(namespace string) ([]nodegen.WorkloadSu
return ret, nil
}

func (c *ControlAPIClient) AuctionDeployWorkload(namespace, bidderId string, req nodegen.StartWorkloadRequestJson) (*nodegen.StartWorkloadResponseJson, error) {
func (c *ControlAPIClient) AuctionDeployWorkload(namespace, bidderId string, req nodegen.StartWorkloadRequest) (*nodegen.StartWorkloadResponse, error) {
reqB, err := json.Marshal(req)
if err != nil {
return nil, err
Expand All @@ -172,7 +172,7 @@ func (c *ControlAPIClient) AuctionDeployWorkload(namespace, bidderId string, req
return nil, err
}

envelope := new(models.Envelope[nodegen.StartWorkloadResponseJson])
envelope := new(models.Envelope[nodegen.StartWorkloadResponse])
err = json.Unmarshal(msg.Data, envelope)
if err != nil {
return nil, err
Expand All @@ -181,7 +181,7 @@ func (c *ControlAPIClient) AuctionDeployWorkload(namespace, bidderId string, req
return &envelope.Data, nil
}

func (c *ControlAPIClient) DeployWorkload(namespace, nodeId string, req nodegen.StartWorkloadRequestJson) (*nodegen.StartWorkloadResponseJson, error) {
func (c *ControlAPIClient) DeployWorkload(namespace, nodeId string, req nodegen.StartWorkloadRequest) (*nodegen.StartWorkloadResponse, error) {
reqB, err := json.Marshal(req)
if err != nil {
return nil, err
Expand All @@ -192,7 +192,7 @@ func (c *ControlAPIClient) DeployWorkload(namespace, nodeId string, req nodegen.
return nil, err
}

envelope := new(models.Envelope[nodegen.StartWorkloadResponseJson])
envelope := new(models.Envelope[nodegen.StartWorkloadResponse])
err = json.Unmarshal(msg.Data, envelope)
if err != nil {
return nil, err
Expand All @@ -201,13 +201,13 @@ func (c *ControlAPIClient) DeployWorkload(namespace, nodeId string, req nodegen.
return &envelope.Data, nil
}

func (c *ControlAPIClient) UndeployWorkload(namespace, workloadId string) (*nodegen.StopWorkloadResponseJson, error) {
func (c *ControlAPIClient) UndeployWorkload(namespace, workloadId string) (*nodegen.StopWorkloadResponse, error) {
msg, err := c.nc.Request(models.UndeployRequestSubject(namespace, workloadId), nil, DefaultRequestTimeout)
if err != nil {
return nil, err
}

envelope := new(models.Envelope[nodegen.StopWorkloadResponseJson])
envelope := new(models.Envelope[nodegen.StopWorkloadResponse])
err = json.Unmarshal(msg.Data, envelope)
if err != nil {
return nil, err
Expand All @@ -216,7 +216,7 @@ func (c *ControlAPIClient) UndeployWorkload(namespace, workloadId string) (*node
return &envelope.Data, nil
}

func (c *ControlAPIClient) GetInfo(nodeId string, req nodegen.NodeInfoRequestJson) (*nodegen.NodeInfoResponseJson, error) {
func (c *ControlAPIClient) GetInfo(nodeId string, req nodegen.NodeInfoRequest) (*nodegen.NodeInfoResponse, error) {
reqB, err := json.Marshal(req)
if err != nil {
return nil, err
Expand All @@ -227,7 +227,7 @@ func (c *ControlAPIClient) GetInfo(nodeId string, req nodegen.NodeInfoRequestJso
return nil, err
}

envelope := new(models.Envelope[nodegen.NodeInfoResponseJson])
envelope := new(models.Envelope[nodegen.NodeInfoResponse])
err = json.Unmarshal(msg.Data, envelope)
if err != nil {
return nil, err
Expand All @@ -236,8 +236,8 @@ func (c *ControlAPIClient) GetInfo(nodeId string, req nodegen.NodeInfoRequestJso
return &envelope.Data, nil
}

func (c *ControlAPIClient) SetLameDuck(nodeId string, delay time.Duration) (*nodegen.LameduckResponseJson, error) {
req := nodegen.LameduckRequestJson{
func (c *ControlAPIClient) SetLameDuck(nodeId string, delay time.Duration) (*nodegen.LameduckResponse, error) {
req := nodegen.LameduckRequest{
Delay: delay.String(),
}

Expand All @@ -251,7 +251,7 @@ func (c *ControlAPIClient) SetLameDuck(nodeId string, delay time.Duration) (*nod
return nil, err
}

envelope := new(models.Envelope[nodegen.LameduckResponseJson])
envelope := new(models.Envelope[nodegen.LameduckResponse])
err = json.Unmarshal(msg.Data, envelope)
if err != nil {
return nil, err
Expand Down Expand Up @@ -302,8 +302,8 @@ func (c *ControlAPIClient) MonitorEvents(namespace, workloadId, eventType string
return ret, nil
}

func (c *ControlAPIClient) CopyWorkload(workloadId, namespace string, targetXkey string) (*nodegen.StartWorkloadRequestJson, error) {
req := &nodegen.CloneWorkloadRequestJson{
func (c *ControlAPIClient) CopyWorkload(workloadId, namespace string, targetXkey string) (*nodegen.StartWorkloadRequest, error) {
req := &nodegen.CloneWorkloadRequest{
NewTargetXkey: targetXkey,
}

Expand All @@ -317,7 +317,7 @@ func (c *ControlAPIClient) CopyWorkload(workloadId, namespace string, targetXkey
return nil, err
}

envelope := new(models.Envelope[nodegen.CloneWorkloadResponseJson])
envelope := new(models.Envelope[nodegen.CloneWorkloadResponse])
err = json.Unmarshal(msg.Data, envelope)
if err != nil {
return nil, err
Expand Down
20 changes: 10 additions & 10 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ func TestAuctionDeployAndFindWorkload(t *testing.T) {

binPath := test.BuildTestBinary(t, "../test/testdata/forever/main.go", workingDir)

resp, err := control.AuctionDeployWorkload(models.NodeSystemNamespace, auctionResp[0].BidderId, gen.StartWorkloadRequestJson{
resp, err := control.AuctionDeployWorkload(models.NodeSystemNamespace, auctionResp[0].BidderId, gen.StartWorkloadRequest{
Description: "Test Workload",
Namespace: models.NodeSystemNamespace,
RetryCount: 3,
Uri: "file://" + binPath,
WorkloadName: "testworkload",
WorkloadRuntype: "service",
WorkloadType: "direct-start",
EncEnvironment: gen.SharedEncEnvJson{
EncEnvironment: gen.EncEnv{
Base64EncryptedEnv: base64.StdEncoding.EncodeToString(encEnv),
EncryptedBy: tAPub,
},
Expand Down Expand Up @@ -255,15 +255,15 @@ func TestDirectDeployAndListWorkloads(t *testing.T) {

binPath := test.BuildTestBinary(t, "../test/testdata/forever/main.go", workingDir)

resp, err := control.DeployWorkload(models.NodeSystemNamespace, test.Node1ServerPublicKey, gen.StartWorkloadRequestJson{
resp, err := control.DeployWorkload(models.NodeSystemNamespace, test.Node1ServerPublicKey, gen.StartWorkloadRequest{
Description: "Test Workload",
Namespace: models.NodeSystemNamespace,
RetryCount: 3,
Uri: "file://" + binPath,
WorkloadName: "testworkload",
WorkloadRuntype: "service",
WorkloadType: "direct-start",
EncEnvironment: gen.SharedEncEnvJson{
EncEnvironment: gen.EncEnv{
Base64EncryptedEnv: base64.StdEncoding.EncodeToString(encEnv),
EncryptedBy: tAPub,
},
Expand Down Expand Up @@ -328,15 +328,15 @@ func TestUndeployWorkload(t *testing.T) {

binPath := test.BuildTestBinary(t, "../test/testdata/forever/main.go", workingDir)

resp, err := control.DeployWorkload(models.NodeSystemNamespace, test.Node1ServerPublicKey, gen.StartWorkloadRequestJson{
resp, err := control.DeployWorkload(models.NodeSystemNamespace, test.Node1ServerPublicKey, gen.StartWorkloadRequest{
Description: "Test Workload",
Namespace: models.NodeSystemNamespace,
RetryCount: 3,
Uri: "file://" + binPath,
WorkloadName: "testworkload",
WorkloadRuntype: "service",
WorkloadType: "direct-start",
EncEnvironment: gen.SharedEncEnvJson{
EncEnvironment: gen.EncEnv{
Base64EncryptedEnv: base64.StdEncoding.EncodeToString(encEnv),
EncryptedBy: tAPub,
},
Expand Down Expand Up @@ -388,7 +388,7 @@ func TestGetNodeInfo(t *testing.T) {
t.Fatal(err)
}

resp, err := control.GetInfo(test.Node1ServerPublicKey, gen.NodeInfoRequestJson{
resp, err := control.GetInfo(test.Node1ServerPublicKey, gen.NodeInfoRequest{
Namespace: models.NodeSystemNamespace,
})
be.NilErr(t, err)
Expand Down Expand Up @@ -432,7 +432,7 @@ func TestSetLameduck(t *testing.T) {
_, err = control.SetLameDuck(test.Node1ServerPublicKey, time.Second*3)
be.NilErr(t, err)

resp, err := control.GetInfo(test.Node1ServerPublicKey, gen.NodeInfoRequestJson{
resp, err := control.GetInfo(test.Node1ServerPublicKey, gen.NodeInfoRequest{
Namespace: models.NodeSystemNamespace,
})
be.NilErr(t, err)
Expand Down Expand Up @@ -487,7 +487,7 @@ func TestCopyWorkload(t *testing.T) {

binPath := test.BuildTestBinary(t, "../test/testdata/forever/main.go", workingDir)

resp, err := control.DeployWorkload(models.NodeSystemNamespace, test.Node1ServerPublicKey, gen.StartWorkloadRequestJson{
resp, err := control.DeployWorkload(models.NodeSystemNamespace, test.Node1ServerPublicKey, gen.StartWorkloadRequest{
Description: "Test Workload",
Argv: []string{"--arg1", "value1"},
Namespace: models.NodeSystemNamespace,
Expand All @@ -496,7 +496,7 @@ func TestCopyWorkload(t *testing.T) {
WorkloadName: "testworkload",
WorkloadRuntype: "service",
WorkloadType: "direct-start",
EncEnvironment: gen.SharedEncEnvJson{
EncEnvironment: gen.EncEnv{
Base64EncryptedEnv: base64.StdEncoding.EncodeToString(encEnv),
EncryptedBy: tAPub,
},
Expand Down
32 changes: 16 additions & 16 deletions api/go/agent.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 724e06d

Please sign in to comment.