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

#3 add GOA generated DSL code

parent b5dd5e4e
No related branches found
No related tags found
1 merge request!3Create SET cache endpoint
......@@ -40,7 +40,7 @@ type CacheGetRequest struct {
// CacheSetRequest is the payload type of the cache service Set method.
type CacheSetRequest struct {
Data []byte
Data interface{}
Key string
Namespace string
Scope string
......
......@@ -8,6 +8,9 @@
package client
import (
"encoding/json"
"fmt"
cache "code.vereign.com/gaiax/tsa/cache/gen/cache"
)
......@@ -35,9 +38,13 @@ func BuildGetPayload(cacheGetKey string, cacheGetNamespace string, cacheGetScope
// BuildSetPayload builds the payload for the cache Set endpoint from CLI flags.
func BuildSetPayload(cacheSetBody string, cacheSetKey string, cacheSetNamespace string, cacheSetScope string) (*cache.CacheSetRequest, error) {
var body []byte
var err error
var body interface{}
{
body = []byte(cacheSetBody)
err = json.Unmarshal([]byte(cacheSetBody), &body)
if err != nil {
return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "\"Quasi ut.\"")
}
}
var key string
{
......
......@@ -73,7 +73,7 @@ func EncodeSetResponse(encoder func(context.Context, http.ResponseWriter) goahtt
func DecodeSetRequest(mux goahttp.Muxer, decoder func(*http.Request) goahttp.Decoder) func(*http.Request) (interface{}, error) {
return func(r *http.Request) (interface{}, error) {
var (
body []byte
body interface{}
err error
)
err = decoder(r).Decode(&body)
......
......@@ -22,7 +22,7 @@ func NewGetCacheGetRequest(key string, namespace string, scope string) *cache.Ca
}
// NewSetCacheSetRequest builds a cache service Set endpoint payload.
func NewSetCacheSetRequest(body []byte, key string, namespace string, scope string) *cache.CacheSetRequest {
func NewSetCacheSetRequest(body interface{}, key string, namespace string, scope string) *cache.CacheSetRequest {
v := body
res := &cache.CacheSetRequest{
Data: v,
......
......@@ -238,15 +238,15 @@ Example:
}
func cacheSetUsage() {
fmt.Fprintf(os.Stderr, `%[1]s [flags] cache set -body STRING -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.
-body STRING:
-body JSON:
-key STRING:
-namespace STRING:
-scope STRING:
Example:
%[1]s cache set --body "UXVhc2kgdXQu" --key "Quasi perspiciatis." --namespace "Accusantium animi non alias." --scope "Esse inventore ullam placeat aut."
%[1]s cache set --body "Quasi ut." --key "Quasi perspiciatis." --namespace "Accusantium animi non alias." --scope "Esse inventore ullam placeat aut."
`, os.Args[0])
}
{"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":"bytes","in":"body","required":true,"schema":{"type":"string","format":"byte"}}],"responses":{"201":{"description":"Created response."}},"schemes":["http"]}}}}
\ No newline at end of file
{"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"]}}}}
\ No newline at end of file
......@@ -90,12 +90,12 @@ paths:
description: Cache entry scope
required: true
type: string
- name: bytes
- name: any
in: body
required: true
schema:
type: string
format: byte
format: binary
responses:
"201":
description: Created response.
......
{"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":"RXQgaWxsdW0gZnVnaWF0IHV0Lg==","format":"binary"},"example":"T3B0aW8gYWxpcXVhbSBlcnJvciBuYW0u"}}},"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
{"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."}]}
\ No newline at end of file
......@@ -192,52 +192,9 @@ paths:
application/json:
schema:
type: string
example:
- 69
- 116
- 32
- 105
- 108
- 108
- 117
- 109
- 32
- 102
- 117
- 103
- 105
- 97
- 116
- 32
- 117
- 116
- 46
example: Et illum fugiat ut.
format: binary
example:
- 79
- 112
- 116
- 105
- 111
- 32
- 97
- 108
- 105
- 113
- 117
- 97
- 109
- 32
- 101
- 114
- 114
- 111
- 114
- 32
- 110
- 97
- 109
- 46
example: Optio aliquam error nam.
responses:
"201":
description: Created response.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment