Initial commit

main v0.0.1
René Jochum 2 years ago
commit 23ac2eff14
Signed by: jochum
GPG Key ID: F7D906F5E51E8E5E

@ -0,0 +1,32 @@
---
kind: pipeline
type: docker
name: default
platform:
os: linux
arch: amd64
trigger:
event:
- cron
- custom
- tag
steps:
- name: build
image: plugins/docker
settings:
registry: registry.fk.jochum.dev
username: robot$jo-micro+drone
password:
from_secret: registry.fk.jochum.dev-robot
dockerfile: ./docker/settings/Dockerfile
repo: registry.fk.jochum.dev/jo-micro/settings
build_args:
- DOCKER_IO=registry.fk.jochum.dev/docker_hub_cache
- DOCKER_ORG_JO_MICRO=registry.fk.jochum.dev/jo-micro
- VERSION=${DRONE_TAG:1}
tags:
- ${DRONE_TAG:1}
- latest

@ -0,0 +1,4 @@
DOCKER_IO=docker.io
DOCKER_ORG_JO_MICRO=docker.io/jomicro
BUILD_MOUNT_FOLDER="~"

10
.gitignore vendored

@ -0,0 +1,10 @@
.env
.DS_STORE
.task/
!.gitkeep
go.work
go.work.sum

@ -0,0 +1,13 @@
Copyright 2022 René Jochum
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@ -0,0 +1,38 @@
[![Build Status](https://drone.fk.jochum.dev/api/badges/jo-micro/settings/status.svg)](https://drone.fk.jochum.dev/jo-micro/settings)
[![Software License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg?style=flat-square)](LICENSE)
[![Go Reference](https://pkg.go.dev/badge/jochum.dev/jo-micro/settings.svg)](https://pkg.go.dev/jochum.dev/jo-micro/settings)
# settings
## Developers corner
### Build podman/docker image
#### Prerequesits
- podman
- [Task](https://taskfile.dev/#/installation)
#### Build
```bash
cp .env.sample .env
task
```
#### Remove everything
```bash
task rm
```
## Authors
- René Jochum - rene@jochum.dev
## License
Its dual licensed:
- Apache-2.0
- GPL-2.0-or-later

@ -0,0 +1,112 @@
version: '3'
dotenv: [".env"]
vars:
GIT_TAG:
sh: git tag --points-at HEAD
GIT_COMMIT:
sh: git rev-parse --short HEAD
GIT_DIRTY:
sh: git status -s
VERSION:
sh: if test "{{.GIT_DIRTY}}" != ""; then echo "{{.GIT_COMMIT}}-dirty"; elif test "{{.GIT_TAG}}" != ""; then echo "{{.GIT_TAG}}"; else echo "{{.GIT_COMMIT}}"; fi
PWD:
sh: echo $PWD
tasks:
default:
cmds:
- task: version
- task: volume
- task: podman
version:
desc: Print the version optained from git
cmds:
- echo "{{.VERSION}}"
volume:
run: "once"
cmds:
- podman volume inspect jo_micro-settings_go 1>/dev/null 2>&1 || podman volume create jo_micro-settings_go
builder:
desc: Run something in the builder container for example "task builder -- go get -u ./..."
cmds:
- podman run --rm
-v "{{.BUILD_MOUNT_FOLDER_INT}}:{{.BUILD_MOUNT_FOLDER_INT}}"
-v "{{.PWD}}:/code"
-v "{{.VOLUME_PATH}}:/go:rw"
{{.DOCKER_ORG_JO_MICRO}}/builder:latest {{.CLI_ARGS}}
vars:
VOLUME_PATH:
sh: podman volume inspect jo_micro-settings_go --format "{{"{{"}}.Mountpoint{{"}}"}}"
BUILD_MOUNT_FOLDER_INT:
sh: realpath {{.BUILD_MOUNT_FOLDER}}
preconditions:
- test -n "{{.CLI_ARGS}}"
protoc:
run: "once"
desc: Generate protobruf go files
sources:
- ./**/*.proto
cmds:
- task: builder
vars:
CLI_ARGS: /scripts/protoc_gen.sh
build:podman:
sources:
- ./go.sum
- ./go.work.sum
- ./cmd/microsettingsd/**/*.go
- ./internal/**/*.go
- /*.go
deps:
- protoc
cmds:
- podman build
-v "{{.BUILD_MOUNT_FOLDER_INT}}:{{.BUILD_MOUNT_FOLDER_INT}}"
-v "{{.VOLUME_PATH}}:/go:rw"
--build-arg CACHEBUST={{.DATE}}
--build-arg VERSION={{.VERSION}}
--build-arg=DOCKER_IO={{.DOCKER_IO}}
--build-arg=DOCKER_ORG_JO_MICRO={{.DOCKER_ORG_JO_MICRO}}
-t {{.DOCKER_ORG_JO_MICRO}}/settings:latest
-f ./docker/settings/Dockerfile
.
vars:
DATE:
sh: date -u -Iseconds
VOLUME_PATH:
sh: podman volume inspect jo_micro-settings_go --format "{{"{{"}}.Mountpoint{{"}}"}}"
BUILD_MOUNT_FOLDER_INT:
sh: realpath {{.BUILD_MOUNT_FOLDER}}
podman:
desc: Generate docker container for jo-micro/settings tagged as {{.DOCKER_ORG_JO_MICRO}}/settings:latest
cmds:
- task: build:podman
tidy:
desc: Run "go mod tidy" in a container
cmds:
- task: builder
vars:
CLI_ARGS: go mod tidy
update:
desc: Run "go get -u ./..." in a container
cmds:
- task: builder
vars:
CLI_ARGS: /scripts/upgrade_deps.sh
rm:
desc: Remove all persistent data
cmds:
- podman image rm {{.DOCKER_ORG_JO_MICRO}}/settings:latest || exit 0
- podman volume rm jo_micro-settings_go || exit 0
- rm -rf $PWD/.task

@ -0,0 +1,9 @@
package config
var (
Version = "not set"
)
const (
Name = "jo.micro.settings"
)

@ -0,0 +1,212 @@
package db
import (
"context"
"encoding/json"
"errors"
"time"
"github.com/google/uuid"
"github.com/uptrace/bun"
"go-micro.dev/v4/util/log"
"jochum.dev/jo-micro/auth2"
"jochum.dev/jo-micro/buncomponent"
"jochum.dev/jo-micro/components"
"jochum.dev/jo-micro/settings/proto/settingspb"
)
type Setting struct {
bun.BaseModel `bun:"settings,alias:s"`
ID uuid.UUID `bun:"id,pk,type:uuid,default:uuid_generate_v4()" json:"id" yaml:"id"`
OwnerID uuid.UUID `bun:"owner_id,type:uuid" json:"owner_id" yaml:"owner_id"`
Service string `json:"service" yaml:"service"`
Name string `json:"name" yaml:"name"`
Content json.RawMessage `bun:"type:jsonb" json:"content" yaml:"content"`
RolesRead []string `bun:"roles_read,array" json:"roles_read" yaml:"roles_read"`
RolesUpdate []string `bun:"roles_update,array" json:"roles_update" yaml:"roles_update"`
// Timestampable
CreatedAt time.Time `bun:"created_at,nullzero,notnull,default:current_timestamp" json:"created_at" yaml:"created_at"`
UpdatedAt bun.NullTime `bun:"updated_at" json:"updated_at" yaml:"updated_at"`
// Softdelete
DeletedAt bun.NullTime `bun:"deleted_at,soft_delete,nullzero" json:"deleted_at" yaml:"deleted_at"`
}
func (s *Setting) UserHasReadPermission(cReg *components.Registry, ctx context.Context) bool {
user, err := auth2.ClientAuthMustReg(cReg).Plugin().Inspect(ctx)
if err != nil {
log.Error(err)
return false
}
if auth2.HasRole(user, auth2.ROLE_SUPERADMIN) {
return true
}
if user.Id == s.OwnerID.String() {
return true
}
if auth2.IntersectsRoles(user, s.RolesRead...) {
return true
}
return false
}
func (s *Setting) UserHasUpdatePermission(cReg *components.Registry, ctx context.Context) bool {
user, err := auth2.ClientAuthMustReg(cReg).Plugin().Inspect(ctx)
if err != nil {
return false
}
if auth2.HasRole(user, auth2.ROLE_SUPERADMIN) {
return true
}
if user.Id == s.OwnerID.String() {
return true
}
if auth2.IntersectsRoles(user, s.RolesUpdate...) {
return true
}
return false
}
func SettingsCreate(cReg *components.Registry, ctx context.Context, in *settingspb.CreateRequest) (*Setting, error) {
var result Setting
if len(in.OwnerId) > 0 {
result.OwnerID = uuid.MustParse(in.OwnerId)
}
result.Service = in.Service
result.Name = in.Name
result.Content = in.Content
result.RolesRead = in.RolesRead
result.RolesUpdate = in.RolesUpdate
_, err := buncomponent.MustReg(cReg).Bun().NewInsert().Model(&result).Exec(ctx)
if err != nil {
return nil, err
}
return &result, nil
}
func SettingsUpdate(cReg *components.Registry, ctx context.Context, id, ownerID, service, name string, content json.RawMessage) (*Setting, error) {
// Fetch current setting
s, err := SettingsGet(cReg, ctx, id, ownerID, service, name)
if err != nil {
return nil, err
}
if !s.UserHasUpdatePermission(cReg, ctx) {
return nil, errors.New("unauthorized")
}
s.Content = content
s.UpdatedAt.Time = time.Now()
// Update
_, err = buncomponent.MustReg(cReg).Bun().NewUpdate().Model(s).Where("id = ?", s.ID).Exec(ctx)
if err != nil {
return nil, err
}
return s, nil
}
func SettingsUpsert(cReg *components.Registry, ctx context.Context, in *settingspb.UpsertRequest) (*Setting, error) {
s, err := SettingsUpdate(cReg, ctx, "", in.OwnerId, in.Service, in.Name, in.Content)
if err == nil {
return s, nil
}
req := settingspb.CreateRequest{}
req.Service = in.Service
req.Name = in.Name
req.Content = in.Content
req.RolesRead = in.RolesRead
req.RolesUpdate = in.RolesUpdate
return SettingsCreate(cReg, ctx, &req)
}
func SettingsGet(cReg *components.Registry, ctx context.Context, id, ownerID, service, name string) (*Setting, error) {
var result Setting
sql := buncomponent.MustReg(cReg).Bun().NewSelect().
Model(&result).
ColumnExpr("s.*").
Limit(1)
if len(id) > 1 {
sql.Where("id = ?", id)
} else if len(service) > 1 {
if len(name) > 1 {
sql.Where("service = ? AND name = ?", service, name)
} else {
sql.Where("service = ?", service)
}
} else if len(ownerID) > 1 {
if len(name) > 1 {
sql.Where("owner_id = ? AND name = ?", ownerID, name)
} else {
sql.Where("owner_id = ?", ownerID)
}
} else {
return nil, errors.New("not enough parameters")
}
err := sql.Scan(ctx)
if err != nil {
return nil, err
}
if !result.UserHasReadPermission(cReg, ctx) {
return nil, errors.New("unauthorized")
}
return &result, nil
}
func SettingsList(cReg *components.Registry, ctx context.Context, id, ownerID, service, name string, limit, offset uint64) ([]Setting, error) {
// Get the data from the db.
var settings []Setting
sql := buncomponent.MustReg(cReg).Bun().NewSelect().
Model(&settings).
ColumnExpr("s.*").
Limit(int(limit)).
Offset(int(offset))
if len(id) > 1 {
sql.Where("id = ?", id)
} else if len(service) > 1 {
if len(name) > 1 {
sql.Where("service = ? AND name = ?", service, name)
} else {
sql.Where("service = ?", service)
}
} else if len(ownerID) > 1 {
if len(name) > 1 {
sql.Where("owner_id = ? AND name = ?", ownerID, name)
} else {
sql.Where("owner_id = ?", ownerID)
}
}
err := sql.Scan(ctx)
if err != nil {
return nil, err
}
var result []Setting
for _, s := range settings {
if s.UserHasReadPermission(cReg, ctx) {
result = append(result, s)
}
}
return result, nil
}

@ -0,0 +1,56 @@
package main
import (
"github.com/urfave/cli/v2"
"go-micro.dev/v4"
"go-micro.dev/v4/logger"
"jochum.dev/jo-micro/auth2"
jwtClient "jochum.dev/jo-micro/auth2/plugins/client/jwt"
"jochum.dev/jo-micro/buncomponent"
"jochum.dev/jo-micro/components"
"jochum.dev/jo-micro/logruscomponent"
"jochum.dev/jo-micro/router"
"jochum.dev/jo-micro/settings/cmd/microsettingsd/config"
"jochum.dev/jo-micro/settings/cmd/microsettingsd/settingshandler"
)
func main() {
service := micro.NewService()
cReg := components.New(service, "settings",
logruscomponent.New(),
auth2.ClientAuthComponent(),
buncomponent.New(),
router.New(),
settingshandler.New(),
)
auth2ClientReg := auth2.ClientAuthMustReg(cReg)
auth2ClientReg.Register(jwtClient.New())
service.Init(
micro.Name(config.Name),
micro.Version(config.Version),
micro.Flags(cReg.AppendFlags([]cli.Flag{})...),
micro.WrapHandler(auth2ClientReg.WrapHandler()),
micro.Action(func(c *cli.Context) error {
// Start/Init the components
if err := cReg.Init(c); err != nil {
logger.Fatal(err)
return err
}
return nil
}),
)
// Run the server
if err := service.Run(); err != nil {
logruscomponent.MustReg(cReg).Logger().Fatal(err)
}
// Stop the components
if err := cReg.Stop(); err != nil {
logger.Fatal(err)
return
}
}

@ -0,0 +1,21 @@
BEGIN;
CREATE TABLE public.settings
(
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
owner_id UUID,
service varchar(32) COLLATE pg_catalog."default",
name varchar(32) COLLATE pg_catalog."default" NOT NULL,
content jsonb,
roles_read varchar(32)[] COLLATE pg_catalog."default",
roles_update varchar(32)[] COLLATE pg_catalog."default",
created_at TIMESTAMPTZ DEFAULT Now() NOT NULL,
updated_at TIMESTAMPTZ NULL,
deleted_at TIMESTAMPTZ NULL
);
CREATE UNIQUE INDEX osn_idx ON public.settings (owner_id, service, name) WHERE (deleted_at IS NULL);
COMMIT;

@ -0,0 +1,8 @@
package main
import (
_ "github.com/go-micro/plugins/v4/broker/nats"
_ "github.com/go-micro/plugins/v4/registry/nats"
_ "github.com/go-micro/plugins/v4/transport/grpc"
_ "github.com/go-micro/plugins/v4/transport/nats"
)

@ -0,0 +1,189 @@
package settingshandler
import (
"context"
"github.com/urfave/cli/v2"
"google.golang.org/protobuf/types/known/timestamppb"
"jochum.dev/jo-micro/auth2"
"jochum.dev/jo-micro/auth2/plugins/verifier/endpointroles"
"jochum.dev/jo-micro/components"
"jochum.dev/jo-micro/logruscomponent"
"jochum.dev/jo-micro/router"
"jochum.dev/jo-micro/settings/cmd/microsettingsd/db"
"jochum.dev/jo-micro/settings/proto/settingspb"
)
const Name = "settingsHandler"
type Handler struct {
cReg *components.Registry
initialized bool
}
func New() *Handler {
return &Handler{}
}
func MustReg(cReg *components.Registry) *Handler {
return cReg.Must(Name).(*Handler)
}
func (h *Handler) Name() string {
return Name
}
func (h *Handler) Priority() int {
return 100
}
func (h *Handler) Initialized() bool {
return h.initialized
}
func (h *Handler) Init(components *components.Registry, cli *cli.Context) error {
if h.initialized {
return nil
}
h.cReg = components
r := router.MustReg(h.cReg)
r.Add(
router.NewRoute(
router.Method(router.MethodGet),
router.Path("/"),
router.Endpoint(settingspb.SettingsService.List),
router.Params("id", "ownerId", "service", "name", "limit", "offset"),
),
router.NewRoute(
router.Method(router.MethodPost),
router.Path("/"),
router.Endpoint(settingspb.SettingsService.Create),
),
router.NewRoute(
router.Method(router.MethodGet),
router.Path("/:id"),
router.Endpoint(settingspb.SettingsService.Get),
router.Params("id", "ownerId", "service", "name"),
),
router.NewRoute(
router.Method(router.MethodPut),
router.Path("/:id"),
router.Endpoint(settingspb.SettingsService.Update),
router.Params("id"),
),
)
authVerifier := endpointroles.NewVerifier(
endpointroles.WithLogrus(logruscomponent.MustReg(h.cReg).Logger()),
)
authVerifier.AddRules(
endpointroles.NewRule(
endpointroles.Endpoint(settingspb.SettingsService.List),
endpointroles.RolesAllow(auth2.RolesServiceAndUsersAndAdmin),
),
endpointroles.NewRule(
endpointroles.Endpoint(settingspb.SettingsService.Create),
endpointroles.RolesAllow(auth2.RolesServiceAndAdmin),
),
endpointroles.NewRule(
endpointroles.Endpoint(settingspb.SettingsService.Get),
endpointroles.RolesAllow(auth2.RolesServiceAndUsersAndAdmin),
),
endpointroles.NewRule(
endpointroles.Endpoint(settingspb.SettingsService.Update),
endpointroles.RolesAllow(auth2.RolesServiceAndUsersAndAdmin),
),
endpointroles.NewRule(
endpointroles.Endpoint(settingspb.SettingsService.Upsert),
endpointroles.RolesAllow(auth2.RolesServiceAndUsersAndAdmin),
),
)
auth2.ClientAuthMustReg(h.cReg).Plugin().AddVerifier(authVerifier)
settingspb.RegisterSettingsServiceHandler(h.cReg.Service().Server(), h)
h.initialized = true
return nil
}
func (h *Handler) Stop() error {
return nil
}
func (h *Handler) Flags(r *components.Registry) []cli.Flag {
return []cli.Flag{}
}
func (h *Handler) Health(context context.Context) error {
return nil
}
func (h *Handler) translateDBSettingToPB(dbs *db.Setting, out *settingspb.Setting) error {
out.Id = dbs.ID.String()
out.OwnerId = dbs.OwnerID.String()
out.Service = dbs.Service
out.Name = dbs.Name
out.Content = dbs.Content
out.CreatedAt = timestamppb.New(dbs.CreatedAt)
if !dbs.UpdatedAt.IsZero() {
out.UpdatedAt = timestamppb.New(dbs.UpdatedAt.Time)
}
return nil
}
func (h *Handler) Create(ctx context.Context, in *settingspb.CreateRequest, out *settingspb.Setting) error {
result, err := db.SettingsCreate(h.cReg, ctx, in)
if err != nil {
return err
}
return h.translateDBSettingToPB(result, out)
}
func (h *Handler) Update(ctx context.Context, in *settingspb.UpdateRequest, out *settingspb.Setting) error {
result, err := db.SettingsUpdate(h.cReg, ctx, in.Id, "", "", "", in.Content)
if err != nil {
return err
}
return h.translateDBSettingToPB(result, out)
}
func (h *Handler) Upsert(ctx context.Context, in *settingspb.UpsertRequest, out *settingspb.Setting) error {
result, err := db.SettingsUpsert(h.cReg, ctx, in)
if err != nil {
return err
}
return h.translateDBSettingToPB(result, out)
}
func (h *Handler) Get(ctx context.Context, in *settingspb.GetRequest, out *settingspb.Setting) error {
result, err := db.SettingsGet(h.cReg, ctx, in.Id, in.OwnerId, in.Service, in.Name)
if err != nil {
return err
}
return h.translateDBSettingToPB(result, out)
}
func (h *Handler) List(ctx context.Context, in *settingspb.ListRequest, out *settingspb.SettingsList) error {
results, err := db.SettingsList(h.cReg, ctx, in.Id, in.OwnerId, in.Service, in.Name, in.Limit, in.Offset)
if err != nil {
return err
}
// Copy the data to the result
for _, result := range results {
row := &settingspb.Setting{}
if err := h.translateDBSettingToPB(&result, row); err != nil {
continue
}
out.Data = append(out.Data, row)
}
return nil
}

@ -0,0 +1,33 @@
ARG DOCKER_IO=docker.io
ARG DOCKER_ORG_JO_MICRO=docker.io/jomicro
# STEP 1 build executable binary
FROM ${DOCKER_ORG_JO_MICRO}/builder:latest AS builder
# Create appuser (/etc/passwd entry for the runner container)
RUN useradd appuser
ARG VERSION
COPY . /code/
WORKDIR /code
ARG CACHEBUST=1
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix cgo -ldflags="-w -s -X 'jochum.dev/jo-micro/settings/internal/config.Version=$VERSION'" -o /usr/local/bin/microsettingsd jochum.dev/jo-micro/settings/cmd/microsettingsd
# STEP 2 build a small image
# start from busybox
FROM ${DOCKER_IO}/library/busybox:latest
LABEL maintainer="René Jochum <rene@jochum.dev>"
# Copy certs, passwd and binary from builder
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /usr/local/bin/microsettingsd /usr/local/bin/microsettingsd
COPY ./cmd/microsettingsd/migrations /migrations
# Run as appuser
USER appuser
CMD [ "/usr/local/bin/microsettingsd" ]

@ -0,0 +1,91 @@
module jochum.dev/jo-micro/settings
go 1.19
require (
github.com/avast/retry-go/v4 v4.1.0
github.com/go-micro/plugins/v4/broker/nats v1.1.1-0.20220908125827-e0369dde429b
github.com/go-micro/plugins/v4/registry/nats v1.1.1-0.20220908125827-e0369dde429b
github.com/go-micro/plugins/v4/transport/grpc v1.1.0
github.com/go-micro/plugins/v4/transport/nats v1.1.1-0.20220908125827-e0369dde429b
github.com/google/uuid v1.3.0
github.com/uptrace/bun v1.1.8
github.com/urfave/cli/v2 v2.16.3
go-micro.dev/v4 v4.8.1
google.golang.org/protobuf v1.28.1
jochum.dev/jo-micro/auth2 v0.5.5
jochum.dev/jo-micro/buncomponent v0.0.7
jochum.dev/jo-micro/components v0.3.2
jochum.dev/jo-micro/logruscomponent v0.0.5
jochum.dev/jo-micro/router v0.4.10
)
require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20220824120805-4b6e5c587895 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
github.com/cloudflare/circl v1.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-acme/lego/v4 v4.8.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.4.2 // indirect
github.com/go-micro/plugins/v4/logger/logrus v1.1.0 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.1.0 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang-migrate/migrate/v4 v4.15.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgx-logrus v0.0.0-20220919124836-b099d8ce75da // indirect
github.com/jackc/pgx/v5 v5.0.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/nats-io/nats.go v1.17.0 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/uptrace/bun/dialect/pgdialect v1.1.8 // indirect
github.com/uptrace/bun/extra/bundebug v1.1.8 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xanzy/ssh-agent v0.3.2 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 // indirect
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/genproto v0.0.0-20220923205249-dd2d53f1fffc // indirect
google.golang.org/grpc v1.49.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)

2011
go.sum

File diff suppressed because it is too large Load Diff

@ -0,0 +1,44 @@
package settings
import (
"encoding/json"
"time"
"github.com/google/uuid"
)
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"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
}
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"`
}

@ -0,0 +1,839 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v3.21.5
// source: settingspb.proto
package settingspb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type CreateRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"`
OwnerId string `protobuf:"bytes,2,opt,name=ownerId,proto3" json:"ownerId,omitempty"`
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
Content []byte `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"`
RolesRead []string `protobuf:"bytes,5,rep,name=rolesRead,proto3" json:"rolesRead,omitempty"`
RolesUpdate []string `protobuf:"bytes,6,rep,name=rolesUpdate,proto3" json:"rolesUpdate,omitempty"`
}
func (x *CreateRequest) Reset() {
*x = CreateRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_settingspb_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CreateRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CreateRequest) ProtoMessage() {}
func (x *CreateRequest) ProtoReflect() protoreflect.Message {
mi := &file_settingspb_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CreateRequest.ProtoReflect.Descriptor instead.
func (*CreateRequest) Descriptor() ([]byte, []int) {
return file_settingspb_proto_rawDescGZIP(), []int{0}
}
func (x *CreateRequest) GetService() string {
if x != nil {
return x.Service
}
return ""
}
func (x *CreateRequest) GetOwnerId() string {
if x != nil {
return x.OwnerId
}
return ""
}
func (x *CreateRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *CreateRequest) GetContent() []byte {
if x != nil {
return x.Content
}
return nil
}
func (x *CreateRequest) GetRolesRead() []string {
if x != nil {
return x.RolesRead
}
return nil
}
func (x *CreateRequest) GetRolesUpdate() []string {
if x != nil {
return x.RolesUpdate
}
return nil
}
type UpdateRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Content []byte `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
}
func (x *UpdateRequest) Reset() {
*x = UpdateRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_settingspb_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UpdateRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdateRequest) ProtoMessage() {}
func (x *UpdateRequest) ProtoReflect() protoreflect.Message {
mi := &file_settingspb_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpdateRequest.ProtoReflect.Descriptor instead.
func (*UpdateRequest) Descriptor() ([]byte, []int) {
return file_settingspb_proto_rawDescGZIP(), []int{1}
}
func (x *UpdateRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *UpdateRequest) GetContent() []byte {
if x != nil {
return x.Content
}
return nil
}
type UpsertRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Selectors
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
OwnerId string `protobuf:"bytes,2,opt,name=ownerId,proto3" json:"ownerId,omitempty"` // For the Update Selector only
Service string `protobuf:"bytes,3,opt,name=service,proto3" json:"service,omitempty"`
Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"`
// Upsert content
Content []byte `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"`
RolesRead []string `protobuf:"bytes,6,rep,name=rolesRead,proto3" json:"rolesRead,omitempty"`
RolesUpdate []string `protobuf:"bytes,7,rep,name=rolesUpdate,proto3" json:"rolesUpdate,omitempty"`
}
func (x *UpsertRequest) Reset() {
*x = UpsertRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_settingspb_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UpsertRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpsertRequest) ProtoMessage() {}
func (x *UpsertRequest) ProtoReflect() protoreflect.Message {
mi := &file_settingspb_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpsertRequest.ProtoReflect.Descriptor instead.
func (*UpsertRequest) Descriptor() ([]byte, []int) {
return file_settingspb_proto_rawDescGZIP(), []int{2}
}
func (x *UpsertRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *UpsertRequest) GetOwnerId() string {
if x != nil {
return x.OwnerId
}
return ""
}
func (x *UpsertRequest) GetService() string {
if x != nil {
return x.Service
}
return ""
}
func (x *UpsertRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *UpsertRequest) GetContent() []byte {
if x != nil {
return x.Content
}
return nil
}
func (x *UpsertRequest) GetRolesRead() []string {
if x != nil {
return x.RolesRead
}
return nil
}
func (x *UpsertRequest) GetRolesUpdate() []string {
if x != nil {
return x.RolesUpdate
}
return nil
}
type GetRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
OwnerId string `protobuf:"bytes,2,opt,name=ownerId,proto3" json:"ownerId,omitempty"`
Service string `protobuf:"bytes,3,opt,name=service,proto3" json:"service,omitempty"`
Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"`
}
func (x *GetRequest) Reset() {
*x = GetRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_settingspb_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetRequest) ProtoMessage() {}
func (x *GetRequest) ProtoReflect() protoreflect.Message {
mi := &file_settingspb_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetRequest.ProtoReflect.Descriptor instead.
func (*GetRequest) Descriptor() ([]byte, []int) {
return file_settingspb_proto_rawDescGZIP(), []int{3}
}
func (x *GetRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *GetRequest) GetOwnerId() string {
if x != nil {
return x.OwnerId
}
return ""
}
func (x *GetRequest) GetService() string {
if x != nil {
return x.Service
}
return ""
}
func (x *GetRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
type ListRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
OwnerId string `protobuf:"bytes,2,opt,name=ownerId,proto3" json:"ownerId,omitempty"`
Service string `protobuf:"bytes,3,opt,name=service,proto3" json:"service,omitempty"`
Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"`
Limit uint64 `protobuf:"varint,5,opt,name=limit,proto3" json:"limit,omitempty"`
Offset uint64 `protobuf:"varint,6,opt,name=offset,proto3" json:"offset,omitempty"`
}
func (x *ListRequest) Reset() {
*x = ListRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_settingspb_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListRequest) ProtoMessage() {}
func (x *ListRequest) ProtoReflect() protoreflect.Message {
mi := &file_settingspb_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListRequest.ProtoReflect.Descriptor instead.
func (*ListRequest) Descriptor() ([]byte, []int) {
return file_settingspb_proto_rawDescGZIP(), []int{4}
}
func (x *ListRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *ListRequest) GetOwnerId() string {
if x != nil {
return x.OwnerId
}
return ""
}
func (x *ListRequest) GetService() string {
if x != nil {
return x.Service
}
return ""
}
func (x *ListRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *ListRequest) GetLimit() uint64 {
if x != nil {
return x.Limit
}
return 0
}
func (x *ListRequest) GetOffset() uint64 {
if x != nil {
return x.Offset
}
return 0
}
type Setting struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Service string `protobuf:"bytes,2,opt,name=service,proto3" json:"service,omitempty"`
OwnerId string `protobuf:"bytes,3,opt,name=ownerId,proto3" json:"ownerId,omitempty"`
Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"`
Content []byte `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"`
CreatedAt *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=createdAt,proto3" json:"createdAt,omitempty"`
UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,7,opt,name=updatedAt,proto3" json:"updatedAt,omitempty"`
}
func (x *Setting) Reset() {
*x = Setting{}
if protoimpl.UnsafeEnabled {
mi := &file_settingspb_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Setting) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Setting) ProtoMessage() {}
func (x *Setting) ProtoReflect() protoreflect.Message {
mi := &file_settingspb_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Setting.ProtoReflect.Descriptor instead.
func (*Setting) Descriptor() ([]byte, []int) {
return file_settingspb_proto_rawDescGZIP(), []int{5}
}
func (x *Setting) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *Setting) GetService() string {
if x != nil {
return x.Service
}
return ""
}
func (x *Setting) GetOwnerId() string {
if x != nil {
return x.OwnerId
}
return ""
}
func (x *Setting) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Setting) GetContent() []byte {
if x != nil {
return x.Content
}
return nil
}
func (x *Setting) GetCreatedAt() *timestamppb.Timestamp {
if x != nil {
return x.CreatedAt
}
return nil
}
func (x *Setting) GetUpdatedAt() *timestamppb.Timestamp {
if x != nil {
return x.UpdatedAt
}
return nil
}
type SettingsList struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Data []*Setting `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"`
Count uint64 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"`
Limit uint64 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"`
Offset uint64 `protobuf:"varint,4,opt,name=offset,proto3" json:"offset,omitempty"`
}
func (x *SettingsList) Reset() {
*x = SettingsList{}
if protoimpl.UnsafeEnabled {
mi := &file_settingspb_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SettingsList) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SettingsList) ProtoMessage() {}
func (x *SettingsList) ProtoReflect() protoreflect.Message {
mi := &file_settingspb_proto_msgTypes[6]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SettingsList.ProtoReflect.Descriptor instead.
func (*SettingsList) Descriptor() ([]byte, []int) {
return file_settingspb_proto_rawDescGZIP(), []int{6}
}
func (x *SettingsList) GetData() []*Setting {
if x != nil {
return x.Data
}
return nil
}
func (x *SettingsList) GetCount() uint64 {
if x != nil {
return x.Count
}
return 0
}
func (x *SettingsList) GetLimit() uint64 {
if x != nil {
return x.Limit
}
return 0
}
func (x *SettingsList) GetOffset() uint64 {
if x != nil {
return x.Offset
}
return 0
}
var File_settingspb_proto protoreflect.FileDescriptor
var file_settingspb_proto_rawDesc = []byte{
0x0a, 0x10, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x12, 0x0a, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x1a, 0x1f,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f,
0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
0xb1, 0x01, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f,
0x77, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x77,
0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e,
0x74, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74,
0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x61, 0x64,
0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x61,
0x64, 0x12, 0x20, 0x0a, 0x0b, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x55, 0x70, 0x64,
0x61, 0x74, 0x65, 0x22, 0x39, 0x0a, 0x0d, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0xc1,
0x01, 0x0a, 0x0d, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64,
0x12, 0x18, 0x0a, 0x07, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x07, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74,
0x65, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65,
0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x61, 0x64, 0x18,
0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x52, 0x65, 0x61, 0x64,
0x12, 0x20, 0x0a, 0x0b, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x18,
0x07, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x72, 0x6f, 0x6c, 0x65, 0x73, 0x55, 0x70, 0x64, 0x61,
0x74, 0x65, 0x22, 0x64, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64,
0x12, 0x18, 0x0a, 0x07, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x07, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x93, 0x01, 0x0a, 0x0b, 0x4c, 0x69, 0x73,
0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x77, 0x6e, 0x65,
0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x77, 0x6e, 0x65, 0x72,
0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20,
0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52,
0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74,
0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x22, 0xef,
0x01, 0x0a, 0x07, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x18,
0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12,
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x05, 0x20,
0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x38, 0x0a, 0x09,
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65,
0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x38, 0x0a, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65,
0x64, 0x41, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65,
0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74,
0x22, 0x7b, 0x0a, 0x0c, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x4c, 0x69, 0x73, 0x74,
0x12, 0x27, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13,
0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x2e, 0x53, 0x65, 0x74, 0x74,
0x69, 0x6e, 0x67, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75,
0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12,
0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05,
0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18,
0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x32, 0xb8, 0x02,
0x0a, 0x0f, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x12, 0x3a, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x19, 0x2e, 0x73, 0x65,
0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67,
0x73, 0x70, 0x62, 0x2e, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x22, 0x00, 0x12, 0x3a, 0x0a,
0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x19, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e,
0x67, 0x73, 0x70, 0x62, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x13, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x2e,
0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x06, 0x55, 0x70, 0x73,
0x65, 0x72, 0x74, 0x12, 0x19, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62,
0x2e, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13,
0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x2e, 0x53, 0x65, 0x74, 0x74,
0x69, 0x6e, 0x67, 0x22, 0x00, 0x12, 0x34, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x16, 0x2e, 0x73,
0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70,
0x62, 0x2e, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x04, 0x4c,
0x69, 0x73, 0x74, 0x12, 0x17, 0x2e, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62,
0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x73,
0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x2e, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e,
0x67, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x22, 0x00, 0x42, 0x3a, 0x5a, 0x38, 0x6a, 0x6f, 0x63, 0x68,
0x75, 0x6d, 0x2e, 0x64, 0x65, 0x76, 0x2f, 0x6a, 0x6f, 0x2d, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x2f,
0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73,
0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x70, 0x62, 0x3b, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e,
0x67, 0x73, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_settingspb_proto_rawDescOnce sync.Once
file_settingspb_proto_rawDescData = file_settingspb_proto_rawDesc
)
func file_settingspb_proto_rawDescGZIP() []byte {
file_settingspb_proto_rawDescOnce.Do(func() {
file_settingspb_proto_rawDescData = protoimpl.X.CompressGZIP(file_settingspb_proto_rawDescData)
})
return file_settingspb_proto_rawDescData
}
var file_settingspb_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_settingspb_proto_goTypes = []interface{}{
(*CreateRequest)(nil), // 0: settingspb.CreateRequest
(*UpdateRequest)(nil), // 1: settingspb.UpdateRequest
(*UpsertRequest)(nil), // 2: settingspb.UpsertRequest
(*GetRequest)(nil), // 3: settingspb.GetRequest
(*ListRequest)(nil), // 4: settingspb.ListRequest
(*Setting)(nil), // 5: settingspb.Setting
(*SettingsList)(nil), // 6: settingspb.SettingsList
(*timestamppb.Timestamp)(nil), // 7: google.protobuf.Timestamp
}
var file_settingspb_proto_depIdxs = []int32{
7, // 0: settingspb.Setting.createdAt:type_name -> google.protobuf.Timestamp
7, // 1: settingspb.Setting.updatedAt:type_name -> google.protobuf.Timestamp
5, // 2: settingspb.SettingsList.data:type_name -> settingspb.Setting
0, // 3: settingspb.SettingsService.Create:input_type -> settingspb.CreateRequest
1, // 4: settingspb.SettingsService.Update:input_type -> settingspb.UpdateRequest
2, // 5: settingspb.SettingsService.Upsert:input_type -> settingspb.UpsertRequest
3, // 6: settingspb.SettingsService.Get:input_type -> settingspb.GetRequest
4, // 7: settingspb.SettingsService.List:input_type -> settingspb.ListRequest
5, // 8: settingspb.SettingsService.Create:output_type -> settingspb.Setting
5, // 9: settingspb.SettingsService.Update:output_type -> settingspb.Setting
5, // 10: settingspb.SettingsService.Upsert:output_type -> settingspb.Setting
5, // 11: settingspb.SettingsService.Get:output_type -> settingspb.Setting
6, // 12: settingspb.SettingsService.List:output_type -> settingspb.SettingsList
8, // [8:13] is the sub-list for method output_type
3, // [3:8] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
}
func init() { file_settingspb_proto_init() }
func file_settingspb_proto_init() {
if File_settingspb_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_settingspb_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CreateRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_settingspb_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UpdateRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_settingspb_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UpsertRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_settingspb_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_settingspb_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_settingspb_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Setting); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_settingspb_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SettingsList); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_settingspb_proto_rawDesc,
NumEnums: 0,
NumMessages: 7,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_settingspb_proto_goTypes,
DependencyIndexes: file_settingspb_proto_depIdxs,
MessageInfos: file_settingspb_proto_msgTypes,
}.Build()
File_settingspb_proto = out.File
file_settingspb_proto_rawDesc = nil
file_settingspb_proto_goTypes = nil
file_settingspb_proto_depIdxs = nil
}

@ -0,0 +1,156 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: settingspb.proto
package settingspb
import (
fmt "fmt"
proto "google.golang.org/protobuf/proto"
_ "google.golang.org/protobuf/types/known/timestamppb"
math "math"
)
import (
context "context"
api "go-micro.dev/v4/api"
client "go-micro.dev/v4/client"
server "go-micro.dev/v4/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for SettingsService service
func NewSettingsServiceEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for SettingsService service
type SettingsService interface {
Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*Setting, error)
Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*Setting, error)
Upsert(ctx context.Context, in *UpsertRequest, opts ...client.CallOption) (*Setting, error)
Get(ctx context.Context, in *GetRequest, opts ...client.CallOption) (*Setting, error)
List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*SettingsList, error)
}
type settingsService struct {
c client.Client
name string
}
func NewSettingsService(name string, c client.Client) SettingsService {
return &settingsService{
c: c,
name: name,
}
}
func (c *settingsService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*Setting, error) {
req := c.c.NewRequest(c.name, "SettingsService.Create", in)
out := new(Setting)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *settingsService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*Setting, error) {
req := c.c.NewRequest(c.name, "SettingsService.Update", in)
out := new(Setting)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *settingsService) Upsert(ctx context.Context, in *UpsertRequest, opts ...client.CallOption) (*Setting, error) {
req := c.c.NewRequest(c.name, "SettingsService.Upsert", in)
out := new(Setting)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *settingsService) Get(ctx context.Context, in *GetRequest, opts ...client.CallOption) (*Setting, error) {
req := c.c.NewRequest(c.name, "SettingsService.Get", in)
out := new(Setting)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *settingsService) List(ctx context.Context, in *ListRequest, opts ...client.CallOption) (*SettingsList, error) {
req := c.c.NewRequest(c.name, "SettingsService.List", in)
out := new(SettingsList)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for SettingsService service
type SettingsServiceHandler interface {
Create(context.Context, *CreateRequest, *Setting) error
Update(context.Context, *UpdateRequest, *Setting) error
Upsert(context.Context, *UpsertRequest, *Setting) error
Get(context.Context, *GetRequest, *Setting) error
List(context.Context, *ListRequest, *SettingsList) error
}
func RegisterSettingsServiceHandler(s server.Server, hdlr SettingsServiceHandler, opts ...server.HandlerOption) error {
type settingsService interface {
Create(ctx context.Context, in *CreateRequest, out *Setting) error
Update(ctx context.Context, in *UpdateRequest, out *Setting) error
Upsert(ctx context.Context, in *UpsertRequest, out *Setting) error
Get(ctx context.Context, in *GetRequest, out *Setting) error
List(ctx context.Context, in *ListRequest, out *SettingsList) error
}
type SettingsService struct {
settingsService
}
h := &settingsServiceHandler{hdlr}
return s.Handle(s.NewHandler(&SettingsService{h}, opts...))
}
type settingsServiceHandler struct {
SettingsServiceHandler
}
func (h *settingsServiceHandler) Create(ctx context.Context, in *CreateRequest, out *Setting) error {
return h.SettingsServiceHandler.Create(ctx, in, out)
}
func (h *settingsServiceHandler) Update(ctx context.Context, in *UpdateRequest, out *Setting) error {
return h.SettingsServiceHandler.Update(ctx, in, out)
}
func (h *settingsServiceHandler) Upsert(ctx context.Context, in *UpsertRequest, out *Setting) error {
return h.SettingsServiceHandler.Upsert(ctx, in, out)
}
func (h *settingsServiceHandler) Get(ctx context.Context, in *GetRequest, out *Setting) error {
return h.SettingsServiceHandler.Get(ctx, in, out)
}
func (h *settingsServiceHandler) List(ctx context.Context, in *ListRequest, out *SettingsList) error {
return h.SettingsServiceHandler.List(ctx, in, out)
}

@ -0,0 +1,80 @@
syntax = "proto3";
package settingspb;
option go_package = "jochum.dev/jo-micro/settings/proto/settingspb;settingspb";
import "google/protobuf/timestamp.proto";
service SettingsService {
rpc Create(CreateRequest) returns (Setting) {}
rpc Update(UpdateRequest) returns (Setting) {}
rpc Upsert(UpsertRequest) returns (Setting) {}
rpc Get(GetRequest) returns (Setting) {}
rpc List(ListRequest) returns (SettingsList) {}
}
message CreateRequest {
string service = 1;
string ownerId = 2;
string name = 3;
bytes content = 4;
repeated string rolesRead = 5;
repeated string rolesUpdate = 6;
}
message UpdateRequest {
string id = 1;
bytes content = 2;
}
message UpsertRequest {
// Selectors
string id = 1;
string ownerId = 2; // For the Update Selector only
string service = 3;
string name = 4;
// Upsert content
bytes content = 5;
repeated string rolesRead = 6;
repeated string rolesUpdate = 7;
}
message GetRequest {
string id = 1;
string ownerId = 2;
string service = 3;
string name = 4;
}
message ListRequest {
string id = 1;
string ownerId = 2;
string service = 3;
string name = 4;
uint64 limit = 5;
uint64 offset = 6;
}
message Setting {
string id = 1;
string service = 2;
string ownerId = 3;
string name = 4;
bytes content = 5;
google.protobuf.Timestamp createdAt = 6;
google.protobuf.Timestamp updatedAt = 7;
}
message SettingsList {
repeated Setting data = 1;
uint64 count = 2;
uint64 limit = 3;
uint64 offset = 4;
}

@ -0,0 +1,307 @@
package settings
import (
"context"
"fmt"
"strings"
"sync"
"go-micro.dev/v4/errors"
"github.com/google/uuid"
"github.com/urfave/cli/v2"
"jochum.dev/jo-micro/components"
"jochum.dev/jo-micro/settings/cmd/microsettingsd/config"
"jochum.dev/jo-micro/settings/proto/settingspb"
"jochum.dev/jo-micro/settings/utils"
)
const Name = "settingsClient"
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,
CreatedAt: in.CreatedAt.AsTime(),
UpdatedAt: in.UpdatedAt.AsTime(),
}, nil
}
type Handler struct {
initialized bool
cReg *components.Registry
cacheGetLock *sync.RWMutex
cacheGet map[string]*Setting
cacheListLock *sync.RWMutex
cacheList map[string][]*Setting
}
func MustReg(cReg *components.Registry) *Handler {
return cReg.Must(Name).(*Handler)
}
func (h *Handler) sClient() (settingspb.SettingsService, error) {
// Wait until the service is here
_, err := utils.ServiceRetryGet(h.cReg.Service(), config.Name, 10)
if err != nil {
return nil, err
}
service := settingspb.NewSettingsService(config.Name, h.cReg.Service().Client())
return service, nil
}
// NewLog creates a new component
func New() *Handler {
return &Handler{
initialized: false,
cacheGetLock: &sync.RWMutex{},
cacheGet: make(map[string]*Setting),
cacheListLock: &sync.RWMutex{},
cacheList: make(map[string][]*Setting),
}
}
func (c *Handler) Priority() int {
return 30
}
func (c *Handler) Name() string {
return Name
}
func (c *Handler) Flags(cReg *components.Registry) []cli.Flag {
return []cli.Flag{
&cli.IntFlag{
Name: fmt.Sprintf("%s_settings_cachetime", strings.ToLower(cReg.FlagPrefix())),
Usage: "Time in seconds where settings caches your request",
Value: 3600,
},
}
}
func (c *Handler) Initialized() bool {
return c.initialized
}
func (h *Handler) Init(cReg *components.Registry, cli *cli.Context) error {
if h.initialized {
return nil
}
h.cReg = cReg
h.initialized = true
return nil
}
func (h *Handler) Stop() error {
h.initialized = false
return nil
}
func (c *Handler) Health(context context.Context) error {
if !c.Initialized() {
return errors.InternalServerError("NOT_INITIALIZED", "Not initialized")
}
return nil
}
func (c *Handler) Get(ctx context.Context, id, ownerId, service, name string) (*Setting, error) {
// Build the request
req := &settingspb.GetRequest{}
cacheKey := ""
if len(id) > 0 {
req.Id = id
cacheKey = id
} else if len(ownerId) > 0 {
req.OwnerId = ownerId
if len(name) > 0 {
req.Name = name
cacheKey = fmt.Sprintf("%s-%s", req.OwnerId, req.Name)
} else {
cacheKey = req.OwnerId
}
} else if len(service) > 0 {
req.Service = service
if len(name) > 0 {
req.Name = name
cacheKey = fmt.Sprintf("%s-%s", req.Service, req.Name)
} else {
cacheKey = req.Service
}
} else {
return nil, errors.BadRequest("INVALID_ARGUMENTS", "invalid arguments")
}
// Check cache and return from cache
c.cacheGetLock.RLock()
if result, ok := c.cacheGet[cacheKey]; ok {
c.cacheGetLock.RUnlock()
return result, nil
}
c.cacheGetLock.RUnlock()
client, err := c.sClient()
if err != nil {
return nil, err
}
result, err := client.Get(ctx, req)
if err != nil {
return nil, fmt.Errorf("%s: %s", cacheKey, err)
}
cResult, err := serviceToClient(result)
if err != nil {
return nil, err
}
// Store the result in cache
c.cacheGetLock.Lock()
c.cacheGet[cacheKey] = cResult
c.cacheGetLock.Unlock()
return cResult, nil
}
func (c *Handler) List(ctx context.Context, id, ownerId, service, name string) ([]*Setting, error) {
// Build the request
req := &settingspb.ListRequest{}
cacheKey := ""
if len(id) > 0 {
req.Id = id
cacheKey = id
} else if len(service) > 0 {
req.Service = service
if len(name) > 0 {
req.Name = name
cacheKey = fmt.Sprintf("%s-%s", req.Service, req.Name)
} else {
cacheKey = req.Service
}
} else if len(ownerId) > 0 {
req.OwnerId = ownerId
if len(name) > 0 {
req.Name = name
cacheKey = fmt.Sprintf("%s-%s", req.OwnerId, req.Name)
} else {
cacheKey = req.OwnerId
}
} else {
return nil, errors.BadRequest("INVALID_ARGUMENTS", "invalid arguments")
}
// Check cache and return from cache
c.cacheListLock.RLock()
if result, ok := c.cacheList[cacheKey]; ok {
c.cacheListLock.RUnlock()
return result, nil
}
c.cacheListLock.RUnlock()
// Fetch
client, err := c.sClient()
if err != nil {
return nil, err
}
result, err := client.List(ctx, req)
if err != nil {
return nil, err
}
cResult := make([]*Setting, len(result.Data))
for idx, s := range result.Data {
cS, err := serviceToClient(s)
if err != nil {
return nil, err
}
cResult[idx] = cS
}
// Store the result in cache
c.cacheListLock.Lock()
c.cacheList[cacheKey] = cResult
c.cacheListLock.Unlock()
return cResult, nil
}
func (c *Handler) Create(ctx context.Context, req CreateRequest) (*Setting, error) {
// Create
client, err := c.sClient()
if err != nil {
return nil, err
}
sReq := &settingspb.CreateRequest{
Service: req.Service,
OwnerId: req.OwnerId,
Name: req.Name,
Content: req.Content,
RolesRead: req.RolesRead,
RolesUpdate: req.RolesUpdate,
}
result, err := client.Create(ctx, sReq)
if err != nil {
return nil, err
}
return serviceToClient(result)
}
func (c *Handler) Update(ctx context.Context, req UpdateRequest) (*Setting, error) {
// Update
client, err := c.sClient()
if err != nil {
return nil, err
}
sReq := &settingspb.UpdateRequest{
Id: req.Id.String(),
Content: req.Content,
}
result, err := client.Update(ctx, sReq)
if err != nil {
return nil, err
}
return serviceToClient(result)
}
func (c *Handler) Upsert(ctx context.Context, req *UpsertRequest) (*Setting, error) {
// Upsert
client, err := c.sClient()
if err != nil {
return nil, err
}
sReq := &settingspb.UpsertRequest{
Id: req.Id.String(),
OwnerId: req.OwnerId.String(),
Service: req.Service,
Name: req.Name,
Content: req.Content,
RolesRead: req.RolesRead,
RolesUpdate: req.RolesUpdate,
}
result, err := client.Upsert(ctx, sReq)
if err != nil {
return nil, err
}
return serviceToClient(result)
}

@ -0,0 +1,46 @@
package utils
import (
"fmt"
"github.com/avast/retry-go/v4"
"go-micro.dev/v4"
)
func ServiceRetryGet(service micro.Service, svcName string, attempts uint) (string, error) {
r := service.Options().Registry
var (
hostAndPort string
)
err := retry.Do(
func() error {
services, err := r.GetService(svcName)
if err == nil {
for _, s := range services {
for _, n := range s.Nodes {
hostAndPort = n.Address
break
}
if hostAndPort != "" {
break
}
}
}
if hostAndPort == "" {
return fmt.Errorf("Service %v not found", svcName)
}
return nil
},
retry.Attempts(attempts),
)
if err != nil {
return "", err
}
return hostAndPort, nil
}
Loading…
Cancel
Save