Skip to content
Snippets Groups Projects
Commit d92a73cd authored by Lyuben Penkovski's avatar Lyuben Penkovski
Browse files

Goa DSL and generated code for create task endpoint

parent 4300dcd9
No related branches found
No related tags found
1 merge request!2Create task HTTP endpoint
Pipeline #49789 failed with stage
in 16 seconds
Showing
with 813 additions and 6 deletions
......@@ -10,7 +10,22 @@ var _ = API("task", func() {
Description("Task Server")
Host("development", func() {
Description("Local development server")
URI("http://localhost:8080")
URI("http://localhost:8082")
})
})
})
var _ = Service("task", func() {
Description("Task service provides endpoints to work with tasks.")
Method("Create", func() {
Description("Create a task and put it in a queue for execution.")
Payload(CreateRequest)
Result(CreateResult)
HTTP(func() {
POST("/v1/task/{taskName}")
Body("data")
Response(StatusOK)
})
})
})
......
// nolint:revive
package design
import . "goa.design/goa/v3/dsl"
var CreateRequest = Type("CreateRequest", func() {
Field(1, "taskName", String, "Task name.")
Field(2, "data", Any, "Data contains JSON payload that will be used for task exection.")
Required("taskName", "data")
})
var CreateResult = Type("CreateResult", func() {
Field(1, "taskID", String, "Unique task identifier.")
Required("taskID")
})
......@@ -14,6 +14,7 @@ import (
"os"
healthc "code.vereign.com/gaiax/tsa/task/gen/http/health/client"
taskc "code.vereign.com/gaiax/tsa/task/gen/http/task/client"
goahttp "goa.design/goa/v3/http"
goa "goa.design/goa/v3/pkg"
)
......@@ -24,12 +25,14 @@ import (
//
func UsageCommands() string {
return `health (liveness|readiness)
task create
`
}
// UsageExamples produces an example of a valid invocation of the CLI tool.
func UsageExamples() string {
return os.Args[0] + ` health liveness` + "\n" +
os.Args[0] + ` task create --body "Minus reprehenderit non quo nihil adipisci." --task-name "Omnis illum rerum."` + "\n" +
""
}
......@@ -48,11 +51,20 @@ func ParseEndpoint(
healthLivenessFlags = flag.NewFlagSet("liveness", flag.ExitOnError)
healthReadinessFlags = flag.NewFlagSet("readiness", flag.ExitOnError)
taskFlags = flag.NewFlagSet("task", flag.ContinueOnError)
taskCreateFlags = flag.NewFlagSet("create", flag.ExitOnError)
taskCreateBodyFlag = taskCreateFlags.String("body", "REQUIRED", "")
taskCreateTaskNameFlag = taskCreateFlags.String("task-name", "REQUIRED", "Task name.")
)
healthFlags.Usage = healthUsage
healthLivenessFlags.Usage = healthLivenessUsage
healthReadinessFlags.Usage = healthReadinessUsage
taskFlags.Usage = taskUsage
taskCreateFlags.Usage = taskCreateUsage
if err := flag.CommandLine.Parse(os.Args[1:]); err != nil {
return nil, nil, err
}
......@@ -70,6 +82,8 @@ func ParseEndpoint(
switch svcn {
case "health":
svcf = healthFlags
case "task":
svcf = taskFlags
default:
return nil, nil, fmt.Errorf("unknown service %q", svcn)
}
......@@ -95,6 +109,13 @@ func ParseEndpoint(
}
case "task":
switch epn {
case "create":
epf = taskCreateFlags
}
}
}
if epf == nil {
......@@ -125,6 +146,13 @@ func ParseEndpoint(
endpoint = c.Readiness()
data = nil
}
case "task":
c := taskc.NewClient(scheme, host, doer, enc, dec, restore)
switch epn {
case "create":
endpoint = c.Create()
data, err = taskc.BuildCreatePayload(*taskCreateBodyFlag, *taskCreateTaskNameFlag)
}
}
}
if err != nil {
......@@ -167,3 +195,28 @@ Example:
%[1]s health readiness
`, os.Args[0])
}
// taskUsage displays the usage of the task command and its subcommands.
func taskUsage() {
fmt.Fprintf(os.Stderr, `Task service provides endpoints to work with tasks.
Usage:
%[1]s [globalflags] task COMMAND [flags]
COMMAND:
create: Create a task and put it in a queue for execution.
Additional help:
%[1]s task COMMAND --help
`, os.Args[0])
}
func taskCreateUsage() {
fmt.Fprintf(os.Stderr, `%[1]s [flags] task create -body JSON -task-name STRING
Create a task and put it in a queue for execution.
-body JSON:
-task-name STRING: Task name.
Example:
%[1]s task create --body "Minus reprehenderit non quo nihil adipisci." --task-name "Omnis illum rerum."
`, os.Args[0])
}
{"swagger":"2.0","info":{"title":"Task Service","description":"The task service is executing tasks created from policies.","version":""},"host":"localhost:8080","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}}}}
\ No newline at end of file
{"swagger":"2.0","info":{"title":"Task Service","description":"The task service is executing tasks created from policies.","version":""},"host":"localhost:8082","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/v1/task/{taskName}":{"post":{"tags":["task"],"summary":"Create task","description":"Create a task and put it in a queue for execution.","operationId":"task#Create","parameters":[{"name":"taskName","in":"path","description":"Task name.","required":true,"type":"string"},{"name":"any","in":"body","description":"Data contains JSON payload that will be used for task exection.","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/TaskCreateResponseBody","required":["taskID"]}}},"schemes":["http"]}}},"definitions":{"TaskCreateResponseBody":{"title":"TaskCreateResponseBody","type":"object","properties":{"taskID":{"type":"string","description":"Unique task identifier.","example":"Corrupti facere sequi tempora eius assumenda molestiae."}},"example":{"taskID":"Laborum sapiente."},"required":["taskID"]}}}
\ No newline at end of file
......@@ -3,7 +3,7 @@ info:
title: Task Service
description: The task service is executing tasks created from policies.
version: ""
host: localhost:8080
host: localhost:8082
consumes:
- application/json
- application/xml
......@@ -35,3 +35,45 @@ paths:
description: OK response.
schemes:
- http
/v1/task/{taskName}:
post:
tags:
- task
summary: Create task
description: Create a task and put it in a queue for execution.
operationId: task#Create
parameters:
- name: taskName
in: path
description: Task name.
required: true
type: string
- name: any
in: body
description: Data contains JSON payload that will be used for task exection.
required: true
schema:
type: string
format: binary
responses:
"200":
description: OK response.
schema:
$ref: '#/definitions/TaskCreateResponseBody'
required:
- taskID
schemes:
- http
definitions:
TaskCreateResponseBody:
title: TaskCreateResponseBody
type: object
properties:
taskID:
type: string
description: Unique task identifier.
example: Corrupti facere sequi tempora eius assumenda molestiae.
example:
taskID: Laborum sapiente.
required:
- taskID
{"openapi":"3.0.3","info":{"title":"Task Service","description":"The task service is executing tasks created from policies.","version":"1.0"},"servers":[{"url":"http://localhost:8080","description":"Task Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}}}}},"components":{},"tags":[{"name":"health","description":"Health service provides health check endpoints."}]}
\ No newline at end of file
{"openapi":"3.0.3","info":{"title":"Task Service","description":"The task service is executing tasks created from policies.","version":"1.0"},"servers":[{"url":"http://localhost:8082","description":"Task Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}}}},"/v1/task/{taskName}":{"post":{"tags":["task"],"summary":"Create task","description":"Create a task and put it in a queue for execution.","operationId":"task#Create","parameters":[{"name":"taskName","in":"path","description":"Task name.","required":true,"schema":{"type":"string","description":"Task name.","example":"Eveniet et eligendi sint quibusdam quia maxime."},"example":"Et ipsa voluptate."}],"requestBody":{"description":"Data contains JSON payload that will be used for task exection.","required":true,"content":{"application/json":{"schema":{"type":"string","description":"Data contains JSON payload that will be used for task exection.","example":"Nam et.","format":"binary"},"example":"Corrupti quia autem dolorum sunt aperiam quaerat."}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateResult"},"example":{"taskID":"Pariatur sequi et."}}}}}}}},"components":{"schemas":{"CreateResult":{"type":"object","properties":{"taskID":{"type":"string","description":"Unique task identifier.","example":"Facere quibusdam voluptate beatae."}},"example":{"taskID":"Eaque excepturi suscipit veritatis nemo."},"required":["taskID"]}}},"tags":[{"name":"health","description":"Health service provides health check endpoints."},{"name":"task","description":"Task service provides endpoints to work with tasks."}]}
\ No newline at end of file
......@@ -4,7 +4,7 @@ info:
description: The task service is executing tasks created from policies.
version: "1.0"
servers:
- url: http://localhost:8080
- url: http://localhost:8082
description: Task Server
paths:
/liveness:
......@@ -25,7 +25,58 @@ paths:
responses:
"200":
description: OK response.
components: {}
/v1/task/{taskName}:
post:
tags:
- task
summary: Create task
description: Create a task and put it in a queue for execution.
operationId: task#Create
parameters:
- name: taskName
in: path
description: Task name.
required: true
schema:
type: string
description: Task name.
example: Eveniet et eligendi sint quibusdam quia maxime.
example: Et ipsa voluptate.
requestBody:
description: Data contains JSON payload that will be used for task exection.
required: true
content:
application/json:
schema:
type: string
description: Data contains JSON payload that will be used for task exection.
example: Nam et.
format: binary
example: Corrupti quia autem dolorum sunt aperiam quaerat.
responses:
"200":
description: OK response.
content:
application/json:
schema:
$ref: '#/components/schemas/CreateResult'
example:
taskID: Pariatur sequi et.
components:
schemas:
CreateResult:
type: object
properties:
taskID:
type: string
description: Unique task identifier.
example: Facere quibusdam voluptate beatae.
example:
taskID: Eaque excepturi suscipit veritatis nemo.
required:
- taskID
tags:
- name: health
description: Health service provides health check endpoints.
- name: task
description: Task service provides endpoints to work with tasks.
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task HTTP client CLI support package
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package client
import (
"encoding/json"
"fmt"
task "code.vereign.com/gaiax/tsa/task/gen/task"
)
// BuildCreatePayload builds the payload for the task Create endpoint from CLI
// flags.
func BuildCreatePayload(taskCreateBody string, taskCreateTaskName string) (*task.CreateRequest, error) {
var err error
var body interface{}
{
err = json.Unmarshal([]byte(taskCreateBody), &body)
if err != nil {
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "\"Minus reprehenderit non quo nihil adipisci.\"")
}
}
var taskName string
{
taskName = taskCreateTaskName
}
v := body
res := &task.CreateRequest{
Data: v,
}
res.TaskName = taskName
return res, nil
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task client HTTP transport
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package client
import (
"context"
"net/http"
goahttp "goa.design/goa/v3/http"
goa "goa.design/goa/v3/pkg"
)
// Client lists the task service endpoint HTTP clients.
type Client struct {
// Create Doer is the HTTP client used to make requests to the Create endpoint.
CreateDoer goahttp.Doer
// RestoreResponseBody controls whether the response bodies are reset after
// decoding so they can be read again.
RestoreResponseBody bool
scheme string
host string
encoder func(*http.Request) goahttp.Encoder
decoder func(*http.Response) goahttp.Decoder
}
// NewClient instantiates HTTP clients for all the task service servers.
func NewClient(
scheme string,
host string,
doer goahttp.Doer,
enc func(*http.Request) goahttp.Encoder,
dec func(*http.Response) goahttp.Decoder,
restoreBody bool,
) *Client {
return &Client{
CreateDoer: doer,
RestoreResponseBody: restoreBody,
scheme: scheme,
host: host,
decoder: dec,
encoder: enc,
}
}
// Create returns an endpoint that makes HTTP requests to the task service
// Create server.
func (c *Client) Create() goa.Endpoint {
var (
encodeRequest = EncodeCreateRequest(c.encoder)
decodeResponse = DecodeCreateResponse(c.decoder, c.RestoreResponseBody)
)
return func(ctx context.Context, v interface{}) (interface{}, error) {
req, err := c.BuildCreateRequest(ctx, v)
if err != nil {
return nil, err
}
err = encodeRequest(req, v)
if err != nil {
return nil, err
}
resp, err := c.CreateDoer.Do(req)
if err != nil {
return nil, goahttp.ErrRequestError("task", "Create", err)
}
return decodeResponse(resp)
}
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task HTTP client encoders and decoders
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package client
import (
"bytes"
"context"
"io/ioutil"
"net/http"
"net/url"
task "code.vereign.com/gaiax/tsa/task/gen/task"
goahttp "goa.design/goa/v3/http"
)
// BuildCreateRequest instantiates a HTTP request object with method and path
// set to call the "task" service "Create" endpoint
func (c *Client) BuildCreateRequest(ctx context.Context, v interface{}) (*http.Request, error) {
var (
taskName string
)
{
p, ok := v.(*task.CreateRequest)
if !ok {
return nil, goahttp.ErrInvalidType("task", "Create", "*task.CreateRequest", v)
}
taskName = p.TaskName
}
u := &url.URL{Scheme: c.scheme, Host: c.host, Path: CreateTaskPath(taskName)}
req, err := http.NewRequest("POST", u.String(), nil)
if err != nil {
return nil, goahttp.ErrInvalidURL("task", "Create", u.String(), err)
}
if ctx != nil {
req = req.WithContext(ctx)
}
return req, nil
}
// EncodeCreateRequest returns an encoder for requests sent to the task Create
// server.
func EncodeCreateRequest(encoder func(*http.Request) goahttp.Encoder) func(*http.Request, interface{}) error {
return func(req *http.Request, v interface{}) error {
p, ok := v.(*task.CreateRequest)
if !ok {
return goahttp.ErrInvalidType("task", "Create", "*task.CreateRequest", v)
}
body := p.Data
if err := encoder(req).Encode(&body); err != nil {
return goahttp.ErrEncodingError("task", "Create", err)
}
return nil
}
}
// DecodeCreateResponse returns a decoder for responses returned by the task
// Create endpoint. restoreBody controls whether the response body should be
// restored after having been read.
func DecodeCreateResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody bool) func(*http.Response) (interface{}, error) {
return func(resp *http.Response) (interface{}, error) {
if restoreBody {
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
resp.Body = ioutil.NopCloser(bytes.NewBuffer(b))
defer func() {
resp.Body = ioutil.NopCloser(bytes.NewBuffer(b))
}()
} else {
defer resp.Body.Close()
}
switch resp.StatusCode {
case http.StatusOK:
var (
body CreateResponseBody
err error
)
err = decoder(resp).Decode(&body)
if err != nil {
return nil, goahttp.ErrDecodingError("task", "Create", err)
}
err = ValidateCreateResponseBody(&body)
if err != nil {
return nil, goahttp.ErrValidationError("task", "Create", err)
}
res := NewCreateResultOK(&body)
return res, nil
default:
body, _ := ioutil.ReadAll(resp.Body)
return nil, goahttp.ErrInvalidResponse("task", "Create", resp.StatusCode, string(body))
}
}
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// HTTP request path constructors for the task service.
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package client
import (
"fmt"
)
// CreateTaskPath returns the URL path to the task service Create HTTP endpoint.
func CreateTaskPath(taskName string) string {
return fmt.Sprintf("/v1/task/%v", taskName)
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task HTTP client types
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package client
import (
task "code.vereign.com/gaiax/tsa/task/gen/task"
goa "goa.design/goa/v3/pkg"
)
// CreateResponseBody is the type of the "task" service "Create" endpoint HTTP
// response body.
type CreateResponseBody struct {
// Unique task identifier.
TaskID *string `form:"taskID,omitempty" json:"taskID,omitempty" xml:"taskID,omitempty"`
}
// NewCreateResultOK builds a "task" service "Create" endpoint result from a
// HTTP "OK" response.
func NewCreateResultOK(body *CreateResponseBody) *task.CreateResult {
v := &task.CreateResult{
TaskID: *body.TaskID,
}
return v
}
// ValidateCreateResponseBody runs the validations defined on CreateResponseBody
func ValidateCreateResponseBody(body *CreateResponseBody) (err error) {
if body.TaskID == nil {
err = goa.MergeErrors(err, goa.MissingFieldError("taskID", "body"))
}
return
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task HTTP server encoders and decoders
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package server
import (
"context"
"io"
"net/http"
task "code.vereign.com/gaiax/tsa/task/gen/task"
goahttp "goa.design/goa/v3/http"
goa "goa.design/goa/v3/pkg"
)
// EncodeCreateResponse returns an encoder for responses returned by the task
// Create endpoint.
func EncodeCreateResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, interface{}) error {
return func(ctx context.Context, w http.ResponseWriter, v interface{}) error {
res, _ := v.(*task.CreateResult)
enc := encoder(ctx, w)
body := NewCreateResponseBody(res)
w.WriteHeader(http.StatusOK)
return enc.Encode(body)
}
}
// DecodeCreateRequest returns a decoder for requests sent to the task Create
// endpoint.
func DecodeCreateRequest(mux goahttp.Muxer, decoder func(*http.Request) goahttp.Decoder) func(*http.Request) (interface{}, error) {
return func(r *http.Request) (interface{}, error) {
var (
body interface{}
err error
)
err = decoder(r).Decode(&body)
if err != nil {
if err == io.EOF {
return nil, goa.MissingPayloadError()
}
return nil, goa.DecodePayloadError(err.Error())
}
var (
taskName string
params = mux.Vars(r)
)
taskName = params["taskName"]
payload := NewCreateRequest(body, taskName)
return payload, nil
}
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// HTTP request path constructors for the task service.
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package server
import (
"fmt"
)
// CreateTaskPath returns the URL path to the task service Create HTTP endpoint.
func CreateTaskPath(taskName string) string {
return fmt.Sprintf("/v1/task/%v", taskName)
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task HTTP server
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package server
import (
"context"
"net/http"
task "code.vereign.com/gaiax/tsa/task/gen/task"
goahttp "goa.design/goa/v3/http"
goa "goa.design/goa/v3/pkg"
)
// Server lists the task service endpoint HTTP handlers.
type Server struct {
Mounts []*MountPoint
Create http.Handler
}
// ErrorNamer is an interface implemented by generated error structs that
// exposes the name of the error as defined in the design.
type ErrorNamer interface {
ErrorName() string
}
// MountPoint holds information about the mounted endpoints.
type MountPoint struct {
// Method is the name of the service method served by the mounted HTTP handler.
Method string
// Verb is the HTTP method used to match requests to the mounted handler.
Verb string
// Pattern is the HTTP request path pattern used to match requests to the
// mounted handler.
Pattern string
}
// New instantiates HTTP handlers for all the task service endpoints using the
// provided encoder and decoder. The handlers are mounted on the given mux
// using the HTTP verb and path defined in the design. errhandler is called
// whenever a response fails to be encoded. formatter is used to format errors
// returned by the service methods prior to encoding. Both errhandler and
// formatter are optional and can be nil.
func New(
e *task.Endpoints,
mux goahttp.Muxer,
decoder func(*http.Request) goahttp.Decoder,
encoder func(context.Context, http.ResponseWriter) goahttp.Encoder,
errhandler func(context.Context, http.ResponseWriter, error),
formatter func(err error) goahttp.Statuser,
) *Server {
return &Server{
Mounts: []*MountPoint{
{"Create", "POST", "/v1/task/{taskName}"},
},
Create: NewCreateHandler(e.Create, mux, decoder, encoder, errhandler, formatter),
}
}
// Service returns the name of the service served.
func (s *Server) Service() string { return "task" }
// Use wraps the server handlers with the given middleware.
func (s *Server) Use(m func(http.Handler) http.Handler) {
s.Create = m(s.Create)
}
// Mount configures the mux to serve the task endpoints.
func Mount(mux goahttp.Muxer, h *Server) {
MountCreateHandler(mux, h.Create)
}
// Mount configures the mux to serve the task endpoints.
func (s *Server) Mount(mux goahttp.Muxer) {
Mount(mux, s)
}
// MountCreateHandler configures the mux to serve the "task" service "Create"
// endpoint.
func MountCreateHandler(mux goahttp.Muxer, h http.Handler) {
f, ok := h.(http.HandlerFunc)
if !ok {
f = func(w http.ResponseWriter, r *http.Request) {
h.ServeHTTP(w, r)
}
}
mux.Handle("POST", "/v1/task/{taskName}", f)
}
// NewCreateHandler creates a HTTP handler which loads the HTTP request and
// calls the "task" service "Create" endpoint.
func NewCreateHandler(
endpoint goa.Endpoint,
mux goahttp.Muxer,
decoder func(*http.Request) goahttp.Decoder,
encoder func(context.Context, http.ResponseWriter) goahttp.Encoder,
errhandler func(context.Context, http.ResponseWriter, error),
formatter func(err error) goahttp.Statuser,
) http.Handler {
var (
decodeRequest = DecodeCreateRequest(mux, decoder)
encodeResponse = EncodeCreateResponse(encoder)
encodeError = goahttp.ErrorEncoder(encoder, formatter)
)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := context.WithValue(r.Context(), goahttp.AcceptTypeKey, r.Header.Get("Accept"))
ctx = context.WithValue(ctx, goa.MethodKey, "Create")
ctx = context.WithValue(ctx, goa.ServiceKey, "task")
payload, err := decodeRequest(r)
if err != nil {
if err := encodeError(ctx, w, err); err != nil {
errhandler(ctx, w, err)
}
return
}
res, err := endpoint(ctx, payload)
if err != nil {
if err := encodeError(ctx, w, err); err != nil {
errhandler(ctx, w, err)
}
return
}
if err := encodeResponse(ctx, w, res); err != nil {
errhandler(ctx, w, err)
}
})
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task HTTP server types
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package server
import (
task "code.vereign.com/gaiax/tsa/task/gen/task"
)
// CreateResponseBody is the type of the "task" service "Create" endpoint HTTP
// response body.
type CreateResponseBody struct {
// Unique task identifier.
TaskID string `form:"taskID" json:"taskID" xml:"taskID"`
}
// NewCreateResponseBody builds the HTTP response body from the result of the
// "Create" endpoint of the "task" service.
func NewCreateResponseBody(res *task.CreateResult) *CreateResponseBody {
body := &CreateResponseBody{
TaskID: res.TaskID,
}
return body
}
// NewCreateRequest builds a task service Create endpoint payload.
func NewCreateRequest(body interface{}, taskName string) *task.CreateRequest {
v := body
res := &task.CreateRequest{
Data: v,
}
res.TaskName = taskName
return res
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task client
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package task
import (
"context"
goa "goa.design/goa/v3/pkg"
)
// Client is the "task" service client.
type Client struct {
CreateEndpoint goa.Endpoint
}
// NewClient initializes a "task" service client given the endpoints.
func NewClient(create goa.Endpoint) *Client {
return &Client{
CreateEndpoint: create,
}
}
// Create calls the "Create" endpoint of the "task" service.
func (c *Client) Create(ctx context.Context, p *CreateRequest) (res *CreateResult, err error) {
var ires interface{}
ires, err = c.CreateEndpoint(ctx, p)
if err != nil {
return
}
return ires.(*CreateResult), nil
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task endpoints
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package task
import (
"context"
goa "goa.design/goa/v3/pkg"
)
// Endpoints wraps the "task" service endpoints.
type Endpoints struct {
Create goa.Endpoint
}
// NewEndpoints wraps the methods of the "task" service with endpoints.
func NewEndpoints(s Service) *Endpoints {
return &Endpoints{
Create: NewCreateEndpoint(s),
}
}
// Use applies the given middleware to all the "task" service endpoints.
func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) {
e.Create = m(e.Create)
}
// NewCreateEndpoint returns an endpoint function that calls the method
// "Create" of service "task".
func NewCreateEndpoint(s Service) goa.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
p := req.(*CreateRequest)
return s.Create(ctx, p)
}
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// task service
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/task/design
package task
import (
"context"
)
// Task service provides endpoints to work with tasks.
type Service interface {
// Create a task and put it in a queue for execution.
Create(context.Context, *CreateRequest) (res *CreateResult, err error)
}
// ServiceName is the name of the service as defined in the design. This is the
// same value that is set in the endpoint request contexts under the ServiceKey
// key.
const ServiceName = "task"
// MethodNames lists the service method names as defined in the design. These
// are the same values that are set in the endpoint request contexts under the
// MethodKey key.
var MethodNames = [1]string{"Create"}
// CreateRequest is the payload type of the task service Create method.
type CreateRequest struct {
// Task name.
TaskName string
// Data contains JSON payload that will be used for task exection.
Data interface{}
}
// CreateResult is the result type of the task service Create method.
type CreateResult struct {
// Unique task identifier.
TaskID string
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment