You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package settings
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/google/uuid"
|
|
"go-micro.dev/v4/errors"
|
|
"jochum.dev/jo-micro/settings/proto/settingspb"
|
|
)
|
|
|
|
type Setting struct {
|
|
Id uuid.UUID `json:"id,omitempty"`
|
|
Service string `json:"service,omitempty"`
|
|
OwnerID uuid.UUID `json:"ownerId,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
Content json.RawMessage `json:"content,omitempty"`
|
|
}
|
|
|
|
func serviceToClient(in *settingspb.Setting) (*Setting, error) {
|
|
id, err := uuid.Parse(in.Id)
|
|
if err != nil {
|
|
return nil, errors.FromError(err)
|
|
}
|
|
|
|
ownerID, _ := uuid.Parse(in.OwnerId)
|
|
|
|
return &Setting{
|
|
Id: id,
|
|
Service: in.Service,
|
|
OwnerID: ownerID,
|
|
Name: in.Name,
|
|
Content: in.Content,
|
|
}, nil
|
|
}
|
|
|
|
type CreateRequest struct {
|
|
Service string `json:"service,omitempty"`
|
|
OwnerId string `json:"ownerId,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
Content []byte `json:"content,omitempty"`
|
|
RolesRead []string `json:"rolesRead,omitempty"`
|
|
RolesUpdate []string `json:"rolesUpdate,omitempty"`
|
|
}
|
|
|
|
type UpdateRequest struct {
|
|
Id uuid.UUID `json:"id,omitempty"`
|
|
Content []byte `json:"content,omitempty"`
|
|
}
|
|
|
|
type UpsertRequest struct {
|
|
// For the Update Selector only
|
|
Id uuid.UUID `json:"id,omitempty"`
|
|
OwnerId uuid.UUID `json:"ownerId,omitempty"`
|
|
Service string `json:"service,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
// Upsert content
|
|
Content []byte `json:"content,omitempty"`
|
|
RolesRead []string `json:"rolesRead,omitempty"`
|
|
RolesUpdate []string `json:"rolesUpdate,omitempty"`
|
|
}
|