bouncer/internal/client/create_layer.go

33 lines
840 B
Go
Raw Permalink Normal View History

2023-04-24 20:52:12 +02:00
package client
import (
"context"
"fmt"
"forge.cadoles.com/cadoles/bouncer/internal/admin"
"forge.cadoles.com/cadoles/bouncer/internal/store"
"github.com/pkg/errors"
)
func (c *Client) CreateLayer(ctx context.Context, proxyName store.ProxyName, layerName store.LayerName, layerType store.LayerType, options store.LayerOptions, funcs ...OptionFunc) (*store.Layer, error) {
request := admin.CreateLayerRequest{
Name: string(layerName),
Type: string(layerType),
Options: options,
}
response := withResponse[admin.CreateLayerResponse]()
path := fmt.Sprintf("/api/v1/proxies/%s/layers", proxyName)
if err := c.apiPost(ctx, path, request, &response); err != nil {
return nil, errors.WithStack(err)
}
if response.Error != nil {
return nil, errors.WithStack(response.Error)
}
return response.Data.Layer, nil
}