Skip to content
Snippets Groups Projects
Commit 9c3207f6 authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

#3 add GOA generated DSL code

parent c43aca38
Branches
Tags
1 merge request!3Create SET cache endpoint
...@@ -28,13 +28,13 @@ func NewClient(get, set goa.Endpoint) *Client { ...@@ -28,13 +28,13 @@ func NewClient(get, set goa.Endpoint) *Client {
} }
// Get calls the "Get" endpoint of the "cache" service. // Get calls the "Get" endpoint of the "cache" service.
func (c *Client) Get(ctx context.Context, p *CacheGetRequest) (res []byte, err error) { func (c *Client) Get(ctx context.Context, p *CacheGetRequest) (res interface{}, err error) {
var ires interface{} var ires interface{}
ires, err = c.GetEndpoint(ctx, p) ires, err = c.GetEndpoint(ctx, p)
if err != nil { if err != nil {
return return
} }
return ires.([]byte), nil return ires.(interface{}), nil
} }
// Set calls the "Set" endpoint of the "cache" service. // Set calls the "Set" endpoint of the "cache" service.
......
...@@ -13,11 +13,9 @@ import ( ...@@ -13,11 +13,9 @@ import (
// Cache service allows storing and retrieving data from distributed cache. // Cache service allows storing and retrieving data from distributed cache.
type Service interface { type Service interface {
// Get value from the cache. The result is a sequence of bytes which the client // Get JSON value from the cache.
// must decode. Get(context.Context, *CacheGetRequest) (res interface{}, err error)
Get(context.Context, *CacheGetRequest) (res []byte, err error) // Set a JSON value in the cache.
// Set value in the cache. The HTTP request body is stored as value and the key
// is assembled from HTTP request headers.
Set(context.Context, *CacheSetRequest) (err error) Set(context.Context, *CacheSetRequest) (err error)
} }
......
...@@ -77,7 +77,7 @@ func DecodeGetResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody ...@@ -77,7 +77,7 @@ func DecodeGetResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody
switch resp.StatusCode { switch resp.StatusCode {
case http.StatusOK: case http.StatusOK:
var ( var (
body []byte body interface{}
err error err error
) )
err = decoder(resp).Decode(&body) err = decoder(resp).Decode(&body)
......
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
// endpoint. // endpoint.
func EncodeGetResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, interface{}) error { func EncodeGetResponse(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 { return func(ctx context.Context, w http.ResponseWriter, v interface{}) error {
res, _ := v.([]byte) res, _ := v.(interface{})
enc := encoder(ctx, w) enc := encoder(ctx, w)
body := res body := res
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
......
...@@ -217,8 +217,8 @@ Usage: ...@@ -217,8 +217,8 @@ Usage:
%[1]s [globalflags] cache COMMAND [flags] %[1]s [globalflags] cache COMMAND [flags]
COMMAND: COMMAND:
get: Get value from the cache. The result is a sequence of bytes which the client must decode. get: Get JSON value from the cache.
set: Set value in the cache. The HTTP request body is stored as value and the key is assembled from HTTP request headers. set: Set a JSON value in the cache.
Additional help: Additional help:
%[1]s cache COMMAND --help %[1]s cache COMMAND --help
...@@ -227,7 +227,7 @@ Additional help: ...@@ -227,7 +227,7 @@ Additional help:
func cacheGetUsage() { func cacheGetUsage() {
fmt.Fprintf(os.Stderr, `%[1]s [flags] cache get -key STRING -namespace STRING -scope STRING fmt.Fprintf(os.Stderr, `%[1]s [flags] cache get -key STRING -namespace STRING -scope STRING
Get value from the cache. The result is a sequence of bytes which the client must decode. Get JSON value from the cache.
-key STRING: -key STRING:
-namespace STRING: -namespace STRING:
-scope STRING: -scope STRING:
...@@ -240,7 +240,7 @@ Example: ...@@ -240,7 +240,7 @@ Example:
func cacheSetUsage() { func cacheSetUsage() {
fmt.Fprintf(os.Stderr, `%[1]s [flags] cache set -body JSON -key STRING -namespace STRING -scope STRING fmt.Fprintf(os.Stderr, `%[1]s [flags] cache set -body JSON -key STRING -namespace STRING -scope STRING
Set value in the cache. The HTTP request body is stored as value and the key is assembled from HTTP request headers. Set a JSON value in the cache.
-body JSON: -body JSON:
-key STRING: -key STRING:
-namespace STRING: -namespace STRING:
......
{"swagger":"2.0","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":""},"host":"localhost:8083","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/cache":{"get":{"tags":["cache"],"summary":"Get cache","description":"Get value from the cache. The result is a sequence of bytes which the client must decode.","operationId":"cache#Get","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":true,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"byte"}}},"schemes":["http"]},"post":{"tags":["cache"],"summary":"Set cache","description":"Set value in the cache. The HTTP request body is stored as value and the key is assembled from HTTP request headers.","operationId":"cache#Set","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":true,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":true,"type":"string"},{"name":"any","in":"body","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"201":{"description":"Created response."}},"schemes":["http"]}}}} {"swagger":"2.0","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":""},"host":"localhost:8083","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/cache":{"get":{"tags":["cache"],"summary":"Get cache","description":"Get JSON value from the cache.","operationId":"cache#Get","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":true,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"}}},"schemes":["http"]},"post":{"tags":["cache"],"summary":"Set cache","description":"Set a JSON value in the cache.","operationId":"cache#Set","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","required":true,"type":"string"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","required":true,"type":"string"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","required":true,"type":"string"},{"name":"any","in":"body","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"201":{"description":"Created response."}},"schemes":["http"]}}}}
\ No newline at end of file \ No newline at end of file
...@@ -40,8 +40,7 @@ paths: ...@@ -40,8 +40,7 @@ paths:
tags: tags:
- cache - cache
summary: Get cache summary: Get cache
description: Get value from the cache. The result is a sequence of bytes which description: Get JSON value from the cache.
the client must decode.
operationId: cache#Get operationId: cache#Get
parameters: parameters:
- name: x-cache-key - name: x-cache-key
...@@ -64,15 +63,14 @@ paths: ...@@ -64,15 +63,14 @@ paths:
description: OK response. description: OK response.
schema: schema:
type: string type: string
format: byte format: binary
schemes: schemes:
- http - http
post: post:
tags: tags:
- cache - cache
summary: Set cache summary: Set cache
description: Set value in the cache. The HTTP request body is stored as value description: Set a JSON value in the cache.
and the key is assembled from HTTP request headers.
operationId: cache#Set operationId: cache#Set
parameters: parameters:
- name: x-cache-key - name: x-cache-key
......
{"openapi":"3.0.3","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":"1.0"},"servers":[{"url":"http://localhost:8083","description":"Cache 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/cache":{"get":{"tags":["cache"],"summary":"Get cache","description":"Get value from the cache. The result is a sequence of bytes which the client must decode.","operationId":"cache#Get","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","example":"UXVpIGl1c3RvIGVuaW0gZXN0IGRvbG9yZXMgZG9sb3JlbSBldC4=","format":"binary"},"example":"UXVpc3F1YW0gYWIgZG9sb3JlcyBkaXN0aW5jdGlvIHF1aXMu"}}}}},"post":{"tags":["cache"],"summary":"Set cache","description":"Set value in the cache. The HTTP request body is stored as value and the key is assembled from HTTP request headers.","operationId":"cache#Set","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string","example":"Et illum fugiat ut.","format":"binary"},"example":"Optio aliquam error nam."}}},"responses":{"201":{"description":"Created response."}}}}},"components":{},"tags":[{"name":"health","description":"Health service provides health check endpoints."},{"name":"cache","description":"Cache service allows storing and retrieving data from distributed cache."}]} {"openapi":"3.0.3","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":"1.0"},"servers":[{"url":"http://localhost:8083","description":"Cache 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/cache":{"get":{"tags":["cache"],"summary":"Get cache","description":"Get JSON value from the cache.","operationId":"cache#Get","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","example":"Qui iusto enim est dolores dolorem et.","format":"binary"},"example":"Quisquam ab dolores distinctio quis."}}}}},"post":{"tags":["cache"],"summary":"Set cache","description":"Set a JSON value in the cache.","operationId":"cache#Set","parameters":[{"name":"x-cache-key","in":"header","description":"Cache entry key","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry key","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-namespace","in":"header","description":"Cache entry namespace","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry namespace","example":"Login"},"example":"Login"},{"name":"x-cache-scope","in":"header","description":"Cache entry scope","allowEmptyValue":true,"required":true,"schema":{"type":"string","description":"Cache entry scope","example":"administration"},"example":"administration"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"string","example":"Et illum fugiat ut.","format":"binary"},"example":"Optio aliquam error nam."}}},"responses":{"201":{"description":"Created response."}}}}},"components":{},"tags":[{"name":"health","description":"Health service provides health check endpoints."},{"name":"cache","description":"Cache service allows storing and retrieving data from distributed cache."}]}
\ No newline at end of file \ No newline at end of file
...@@ -30,8 +30,7 @@ paths: ...@@ -30,8 +30,7 @@ paths:
tags: tags:
- cache - cache
summary: Get cache summary: Get cache
description: Get value from the cache. The result is a sequence of bytes which description: Get JSON value from the cache.
the client must decode.
operationId: cache#Get operationId: cache#Get
parameters: parameters:
- name: x-cache-key - name: x-cache-key
...@@ -71,89 +70,14 @@ paths: ...@@ -71,89 +70,14 @@ paths:
application/json: application/json:
schema: schema:
type: string type: string
example: example: Qui iusto enim est dolores dolorem et.
- 81
- 117
- 105
- 32
- 105
- 117
- 115
- 116
- 111
- 32
- 101
- 110
- 105
- 109
- 32
- 101
- 115
- 116
- 32
- 100
- 111
- 108
- 111
- 114
- 101
- 115
- 32
- 100
- 111
- 108
- 111
- 114
- 101
- 109
- 32
- 101
- 116
- 46
format: binary format: binary
example: example: Quisquam ab dolores distinctio quis.
- 81
- 117
- 105
- 115
- 113
- 117
- 97
- 109
- 32
- 97
- 98
- 32
- 100
- 111
- 108
- 111
- 114
- 101
- 115
- 32
- 100
- 105
- 115
- 116
- 105
- 110
- 99
- 116
- 105
- 111
- 32
- 113
- 117
- 105
- 115
- 46
post: post:
tags: tags:
- cache - cache
summary: Set cache summary: Set cache
description: Set value in the cache. The HTTP request body is stored as value description: Set a JSON value in the cache.
and the key is assembled from HTTP request headers.
operationId: cache#Set operationId: cache#Set
parameters: parameters:
- name: x-cache-key - name: x-cache-key
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment