oa backend init with go zero

v3
veypi 4 months ago
parent 0349640df7
commit 54a200f297

3
oa/.gitignore vendored

@ -0,0 +1,3 @@
build
static
dist

@ -0,0 +1,34 @@
#
# Makefile
# Copyright (C) 2024 veypi <i@veypi.com>
# 2024-07-31 18:38
# Distributed under terms of the MIT license.
#
db=mysql://root:123456@localhost:3306/oa
all:
@echo "Makefile needs your attention"
.PHONY:build
build:
@go build -o ./build/oa
fmt:
@goctl api format --dir ./api
gen_sql:
@goctl model mysql ddl -c --database oa -d ./models -s ./protoc/sql/base.sql
# add sql script
# sqlx migrate --source ./protoc/sql add base
# create database
# sqlx database create -D $(db)
gen_db:
@sqlx database drop -D $(db)
@sqlx database create -D $(db)
@sqlx migrate --source ./protoc/sql run -D $(db)
gen_api:
@goctl api go -api ./protoc/api/all.api -dir ./

@ -0,0 +1,3 @@
Name: main
Host: 0.0.0.0
Port: 8888

@ -0,0 +1,50 @@
module oa
go 1.21.5
require github.com/zeromicro/go-zero v1.7.0
require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/redis/go-redis/v9 v9.6.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

@ -0,0 +1,141 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA=
github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQevyi/DJpoj6mi0=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/openzipkin/zipkin-go v0.4.3 h1:9EGwpqkgnwdEIJ+Od7QVSEIH+ocmm5nPat0G7sjsSdg=
github.com/openzipkin/zipkin-go v0.4.3/go.mod h1:M9wCJZFWCo2RiY+o1eBCEMe0Dp2S5LDHcMZmk3RmK7c=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
github.com/zeromicro/go-zero v1.7.0 h1:B+y7tUVlo3qVQ6F0I0R9bi+Dq4I1QdO9ZB+dz1r0p1s=
github.com/zeromicro/go-zero v1.7.0/go.mod h1:ypW4PzQI+jUrMcNJDDQ+7YW+pE+tMua9Xj/pmtmS1Dc=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 h1:t6wl9SPayj+c7lEIFgm4ooDBZVb01IhLB4InpomhRw8=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0/go.mod h1:iSDOcsnSA5INXzZtwaBPrKp/lWu/V14Dd+llD0oI2EA=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 h1:Mw5xcxMwlqoJd97vwPxA8isEaIoxsta9/Q51+TTJLGE=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0/go.mod h1:CQNu9bj7o7mC6U7+CA/schKEYakYXWr79ucDHTMGhCM=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 h1:Xw8U6u2f8DK2XAkGRFV7BBLENgnTGX9i4rQRxJf+/vs=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0/go.mod h1:6KW1Fm6R/s6Z3PGXwSJN2K4eT6wQB3vXX6CVnYX9NmM=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 h1:s0PHtIkN+3xrbDOpt2M8OTG92cWqUESvzh2MxiR5xY8=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0/go.mod h1:hZlFbDbRt++MMPCCfSJfmhkGIWnX1h3XjkfxZUjLrIA=
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 h1:3evrL5poBuh1KF51D9gO/S+N/1msnm4DaBqs/rpXUqY=
go.opentelemetry.io/otel/exporters/zipkin v1.24.0/go.mod h1:0EHgD8R0+8yRhUYJOGR8Hfg2dpiJQxDOszd5smVO9wM=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d h1:kHjw/5UfflP/L5EbledDrcG4C2597RtymmGRZvHiCuY=
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d/go.mod h1:mw8MG/Qz5wfgYr6VqVCiZcHe/GJEfI+oGGDCohaVgB0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=

@ -0,0 +1,7 @@
package config
import "github.com/zeromicro/go-zero/rest"
type Config struct {
rest.RestConf
}

@ -0,0 +1,28 @@
package app
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"oa/internal/logic/app"
"oa/internal/svc"
"oa/internal/types"
)
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := app.NewLoginLogic(r.Context(), svcCtx)
resp, err := l.Login(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

@ -0,0 +1,36 @@
// Code generated by goctl. DO NOT EDIT.
package handler
import (
"net/http"
app "oa/internal/handler/app"
user "oa/internal/handler/user"
"oa/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/login",
Handler: app.LoginHandler(serverCtx),
},
},
rest.WithPrefix("/api/app"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/login",
Handler: user.LoginHandler(serverCtx),
},
},
rest.WithPrefix("/api/user"),
)
}

@ -0,0 +1,28 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"oa/internal/logic/user"
"oa/internal/svc"
"oa/internal/types"
)
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.LoginReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewLoginLogic(r.Context(), svcCtx)
resp, err := l.Login(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

@ -0,0 +1,30 @@
package app
import (
"context"
"oa/internal/svc"
"oa/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type LoginLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
return &LoginLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *LoginLogic) Login(req *types.AppReq) (resp *types.AppResp, err error) {
// todo: add your logic here and delete this line
return
}

@ -0,0 +1,30 @@
package user
import (
"context"
"oa/internal/svc"
"oa/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type LoginLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
return &LoginLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *LoginLogic) Login(req *types.LoginReq) (resp *types.LoginResp, err error) {
// todo: add your logic here and delete this line
return
}

@ -0,0 +1,15 @@
package svc
import (
"oa/internal/config"
)
type ServiceContext struct {
Config config.Config
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}

@ -0,0 +1,33 @@
// Code generated by goctl. DO NOT EDIT.
package types
type AppReq struct {
Error
Appname string `json:"username"`
Password string `json:"password"`
}
type AppResp struct {
Id int64 `json:"id"`
Name string `json:"name"`
Token string `json:"token"`
ExpireAt string `json:"expireAt"`
}
type LoginReq struct {
Error
Username string `json:"username"`
Password string `json:"password"`
}
type LoginResp struct {
Id int64 `json:"id"`
Name string `json:"name"`
Token string `json:"token"`
ExpireAt string `json:"expireAt"`
}
type Error struct {
Status string `json:"status"`
Code int `json:"code"`
}

@ -0,0 +1,31 @@
package main
import (
"flag"
"fmt"
"oa/internal/config"
"oa/internal/handler"
"oa/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/main.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
}

@ -0,0 +1,27 @@
package models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ AccessModel = (*customAccessModel)(nil)
type (
// AccessModel is an interface to be customized, add more methods here,
// and implement the added methods in customAccessModel.
AccessModel interface {
accessModel
}
customAccessModel struct {
*defaultAccessModel
}
)
// NewAccessModel returns a model for the database table.
func NewAccessModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) AccessModel {
return &customAccessModel{
defaultAccessModel: newAccessModel(conn, c, opts...),
}
}

@ -0,0 +1,117 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
accessFieldNames = builder.RawFieldNames(&Access{})
accessRows = strings.Join(accessFieldNames, ",")
accessRowsExpectAutoSet = strings.Join(stringx.Remove(accessFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
accessRowsWithPlaceHolder = strings.Join(stringx.Remove(accessFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheOaAccessIdPrefix = "cache:oa:access:id:"
)
type (
accessModel interface {
Insert(ctx context.Context, data *Access) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*Access, error)
Update(ctx context.Context, data *Access) error
Delete(ctx context.Context, id int64) error
}
defaultAccessModel struct {
sqlc.CachedConn
table string
}
Access struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
AccessId int64 `db:"access_id"`
Name string `db:"name"`
RoleId sql.NullString `db:"role_id"`
UserId sql.NullString `db:"user_id"`
Rid sql.NullString `db:"rid"` // 资源子id
Level int64 `db:"level"`
}
)
func newAccessModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultAccessModel {
return &defaultAccessModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`access`",
}
}
func (m *defaultAccessModel) Delete(ctx context.Context, id int64) error {
oaAccessIdKey := fmt.Sprintf("%s%v", cacheOaAccessIdPrefix, id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, oaAccessIdKey)
return err
}
func (m *defaultAccessModel) FindOne(ctx context.Context, id int64) (*Access, error) {
oaAccessIdKey := fmt.Sprintf("%s%v", cacheOaAccessIdPrefix, id)
var resp Access
err := m.QueryRowCtx(ctx, &resp, oaAccessIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", accessRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAccessModel) Insert(ctx context.Context, data *Access) (sql.Result, error) {
oaAccessIdKey := fmt.Sprintf("%s%v", cacheOaAccessIdPrefix, data.Id)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, accessRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.AccessId, data.Name, data.RoleId, data.UserId, data.Rid, data.Level)
}, oaAccessIdKey)
return ret, err
}
func (m *defaultAccessModel) Update(ctx context.Context, data *Access) error {
oaAccessIdKey := fmt.Sprintf("%s%v", cacheOaAccessIdPrefix, data.Id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, accessRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.AccessId, data.Name, data.RoleId, data.UserId, data.Rid, data.Level, data.Id)
}, oaAccessIdKey)
return err
}
func (m *defaultAccessModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheOaAccessIdPrefix, primary)
}
func (m *defaultAccessModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", accessRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultAccessModel) tableName() string {
return m.table
}

@ -0,0 +1,27 @@
package models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ AppModel = (*customAppModel)(nil)
type (
// AppModel is an interface to be customized, add more methods here,
// and implement the added methods in customAppModel.
AppModel interface {
appModel
}
customAppModel struct {
*defaultAppModel
}
)
// NewAppModel returns a model for the database table.
func NewAppModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) AppModel {
return &customAppModel{
defaultAppModel: newAppModel(conn, c, opts...),
}
}

@ -0,0 +1,121 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
appFieldNames = builder.RawFieldNames(&App{})
appRows = strings.Join(appFieldNames, ",")
appRowsExpectAutoSet = strings.Join(stringx.Remove(appFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
appRowsWithPlaceHolder = strings.Join(stringx.Remove(appFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheOaAppIdPrefix = "cache:oa:app:id:"
)
type (
appModel interface {
Insert(ctx context.Context, data *App) (sql.Result, error)
FindOne(ctx context.Context, id string) (*App, error)
Update(ctx context.Context, data *App) error
Delete(ctx context.Context, id string) error
}
defaultAppModel struct {
sqlc.CachedConn
table string
}
App struct {
Id string `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
Key string `db:"_key"`
Name string `db:"name"`
Icon sql.NullString `db:"icon"`
Des sql.NullString `db:"des"`
UserCount int64 `db:"user_count"`
Hide int64 `db:"hide"`
JoinMethod int64 `db:"join_method"`
RoleId sql.NullString `db:"role_id"`
Host string `db:"host"`
Redirect string `db:"redirect"`
Status int64 `db:"status"` // 状态0ok1disabled
}
)
func newAppModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultAppModel {
return &defaultAppModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`app`",
}
}
func (m *defaultAppModel) Delete(ctx context.Context, id string) error {
oaAppIdKey := fmt.Sprintf("%s%v", cacheOaAppIdPrefix, id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, oaAppIdKey)
return err
}
func (m *defaultAppModel) FindOne(ctx context.Context, id string) (*App, error) {
oaAppIdKey := fmt.Sprintf("%s%v", cacheOaAppIdPrefix, id)
var resp App
err := m.QueryRowCtx(ctx, &resp, oaAppIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppModel) Insert(ctx context.Context, data *App) (sql.Result, error) {
oaAppIdKey := fmt.Sprintf("%s%v", cacheOaAppIdPrefix, data.Id)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, appRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Id, data.Created, data.Updated, data.Key, data.Name, data.Icon, data.Des, data.UserCount, data.Hide, data.JoinMethod, data.RoleId, data.Host, data.Redirect, data.Status)
}, oaAppIdKey)
return ret, err
}
func (m *defaultAppModel) Update(ctx context.Context, data *App) error {
oaAppIdKey := fmt.Sprintf("%s%v", cacheOaAppIdPrefix, data.Id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, appRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, data.Created, data.Updated, data.Key, data.Name, data.Icon, data.Des, data.UserCount, data.Hide, data.JoinMethod, data.RoleId, data.Host, data.Redirect, data.Status, data.Id)
}, oaAppIdKey)
return err
}
func (m *defaultAppModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheOaAppIdPrefix, primary)
}
func (m *defaultAppModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultAppModel) tableName() string {
return m.table
}

@ -0,0 +1,27 @@
package models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ AppUserModel = (*customAppUserModel)(nil)
type (
// AppUserModel is an interface to be customized, add more methods here,
// and implement the added methods in customAppUserModel.
AppUserModel interface {
appUserModel
}
customAppUserModel struct {
*defaultAppUserModel
}
)
// NewAppUserModel returns a model for the database table.
func NewAppUserModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) AppUserModel {
return &customAppUserModel{
defaultAppUserModel: newAppUserModel(conn, c, opts...),
}
}

@ -0,0 +1,148 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
appUserFieldNames = builder.RawFieldNames(&AppUser{})
appUserRows = strings.Join(appUserFieldNames, ",")
appUserRowsExpectAutoSet = strings.Join(stringx.Remove(appUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
appUserRowsWithPlaceHolder = strings.Join(stringx.Remove(appUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheOaAppUserIdPrefix = "cache:oa:appUser:id:"
cacheOaAppUserUserIdAppIdPrefix = "cache:oa:appUser:userId:appId:"
)
type (
appUserModel interface {
Insert(ctx context.Context, data *AppUser) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*AppUser, error)
FindOneByUserIdAppId(ctx context.Context, userId string, appId string) (*AppUser, error)
Update(ctx context.Context, data *AppUser) error
Delete(ctx context.Context, id int64) error
}
defaultAppUserModel struct {
sqlc.CachedConn
table string
}
AppUser struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
UserId string `db:"user_id"`
Status int64 `db:"status"` // 0: ok,1:disabled,2:applying,3:deny
}
)
func newAppUserModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultAppUserModel {
return &defaultAppUserModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`app_user`",
}
}
func (m *defaultAppUserModel) Delete(ctx context.Context, id int64) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
oaAppUserIdKey := fmt.Sprintf("%s%v", cacheOaAppUserIdPrefix, id)
oaAppUserUserIdAppIdKey := fmt.Sprintf("%s%v:%v", cacheOaAppUserUserIdAppIdPrefix, data.UserId, data.AppId)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, oaAppUserIdKey, oaAppUserUserIdAppIdKey)
return err
}
func (m *defaultAppUserModel) FindOne(ctx context.Context, id int64) (*AppUser, error) {
oaAppUserIdKey := fmt.Sprintf("%s%v", cacheOaAppUserIdPrefix, id)
var resp AppUser
err := m.QueryRowCtx(ctx, &resp, oaAppUserIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appUserRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppUserModel) FindOneByUserIdAppId(ctx context.Context, userId string, appId string) (*AppUser, error) {
oaAppUserUserIdAppIdKey := fmt.Sprintf("%s%v:%v", cacheOaAppUserUserIdAppIdPrefix, userId, appId)
var resp AppUser
err := m.QueryRowIndexCtx(ctx, &resp, oaAppUserUserIdAppIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `user_id` = ? and `app_id` = ? limit 1", appUserRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, userId, appId); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppUserModel) Insert(ctx context.Context, data *AppUser) (sql.Result, error) {
oaAppUserIdKey := fmt.Sprintf("%s%v", cacheOaAppUserIdPrefix, data.Id)
oaAppUserUserIdAppIdKey := fmt.Sprintf("%s%v:%v", cacheOaAppUserUserIdAppIdPrefix, data.UserId, data.AppId)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, appUserRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.UserId, data.Status)
}, oaAppUserIdKey, oaAppUserUserIdAppIdKey)
return ret, err
}
func (m *defaultAppUserModel) Update(ctx context.Context, newData *AppUser) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
oaAppUserIdKey := fmt.Sprintf("%s%v", cacheOaAppUserIdPrefix, data.Id)
oaAppUserUserIdAppIdKey := fmt.Sprintf("%s%v:%v", cacheOaAppUserUserIdAppIdPrefix, data.UserId, data.AppId)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, appUserRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.AppId, newData.UserId, newData.Status, newData.Id)
}, oaAppUserIdKey, oaAppUserUserIdAppIdKey)
return err
}
func (m *defaultAppUserModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheOaAppUserIdPrefix, primary)
}
func (m *defaultAppUserModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appUserRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultAppUserModel) tableName() string {
return m.table
}

@ -0,0 +1,27 @@
package models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ ResourceModel = (*customResourceModel)(nil)
type (
// ResourceModel is an interface to be customized, add more methods here,
// and implement the added methods in customResourceModel.
ResourceModel interface {
resourceModel
}
customResourceModel struct {
*defaultResourceModel
}
)
// NewResourceModel returns a model for the database table.
func NewResourceModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ResourceModel {
return &customResourceModel{
defaultResourceModel: newResourceModel(conn, c, opts...),
}
}

@ -0,0 +1,148 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
resourceFieldNames = builder.RawFieldNames(&Resource{})
resourceRows = strings.Join(resourceFieldNames, ",")
resourceRowsExpectAutoSet = strings.Join(stringx.Remove(resourceFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
resourceRowsWithPlaceHolder = strings.Join(stringx.Remove(resourceFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheOaResourceIdPrefix = "cache:oa:resource:id:"
cacheOaResourceAppIdNamePrefix = "cache:oa:resource:appId:name:"
)
type (
resourceModel interface {
Insert(ctx context.Context, data *Resource) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*Resource, error)
FindOneByAppIdName(ctx context.Context, appId string, name string) (*Resource, error)
Update(ctx context.Context, data *Resource) error
Delete(ctx context.Context, id int64) error
}
defaultResourceModel struct {
sqlc.CachedConn
table string
}
Resource struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
Name string `db:"name"`
Des sql.NullString `db:"des"`
}
)
func newResourceModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultResourceModel {
return &defaultResourceModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`resource`",
}
}
func (m *defaultResourceModel) Delete(ctx context.Context, id int64) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
oaResourceAppIdNameKey := fmt.Sprintf("%s%v:%v", cacheOaResourceAppIdNamePrefix, data.AppId, data.Name)
oaResourceIdKey := fmt.Sprintf("%s%v", cacheOaResourceIdPrefix, id)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, oaResourceAppIdNameKey, oaResourceIdKey)
return err
}
func (m *defaultResourceModel) FindOne(ctx context.Context, id int64) (*Resource, error) {
oaResourceIdKey := fmt.Sprintf("%s%v", cacheOaResourceIdPrefix, id)
var resp Resource
err := m.QueryRowCtx(ctx, &resp, oaResourceIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resourceRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultResourceModel) FindOneByAppIdName(ctx context.Context, appId string, name string) (*Resource, error) {
oaResourceAppIdNameKey := fmt.Sprintf("%s%v:%v", cacheOaResourceAppIdNamePrefix, appId, name)
var resp Resource
err := m.QueryRowIndexCtx(ctx, &resp, oaResourceAppIdNameKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `app_id` = ? and `name` = ? limit 1", resourceRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, appId, name); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultResourceModel) Insert(ctx context.Context, data *Resource) (sql.Result, error) {
oaResourceAppIdNameKey := fmt.Sprintf("%s%v:%v", cacheOaResourceAppIdNamePrefix, data.AppId, data.Name)
oaResourceIdKey := fmt.Sprintf("%s%v", cacheOaResourceIdPrefix, data.Id)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, resourceRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.Name, data.Des)
}, oaResourceAppIdNameKey, oaResourceIdKey)
return ret, err
}
func (m *defaultResourceModel) Update(ctx context.Context, newData *Resource) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
oaResourceAppIdNameKey := fmt.Sprintf("%s%v:%v", cacheOaResourceAppIdNamePrefix, data.AppId, data.Name)
oaResourceIdKey := fmt.Sprintf("%s%v", cacheOaResourceIdPrefix, data.Id)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, resourceRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.AppId, newData.Name, newData.Des, newData.Id)
}, oaResourceAppIdNameKey, oaResourceIdKey)
return err
}
func (m *defaultResourceModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheOaResourceIdPrefix, primary)
}
func (m *defaultResourceModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resourceRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultResourceModel) tableName() string {
return m.table
}

@ -0,0 +1,27 @@
package models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ RoleModel = (*customRoleModel)(nil)
type (
// RoleModel is an interface to be customized, add more methods here,
// and implement the added methods in customRoleModel.
RoleModel interface {
roleModel
}
customRoleModel struct {
*defaultRoleModel
}
)
// NewRoleModel returns a model for the database table.
func NewRoleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) RoleModel {
return &customRoleModel{
defaultRoleModel: newRoleModel(conn, c, opts...),
}
}

@ -0,0 +1,114 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
roleFieldNames = builder.RawFieldNames(&Role{})
roleRows = strings.Join(roleFieldNames, ",")
roleRowsExpectAutoSet = strings.Join(stringx.Remove(roleFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
roleRowsWithPlaceHolder = strings.Join(stringx.Remove(roleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheOaRoleIdPrefix = "cache:oa:role:id:"
)
type (
roleModel interface {
Insert(ctx context.Context, data *Role) (sql.Result, error)
FindOne(ctx context.Context, id string) (*Role, error)
Update(ctx context.Context, data *Role) error
Delete(ctx context.Context, id string) error
}
defaultRoleModel struct {
sqlc.CachedConn
table string
}
Role struct {
Id string `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
Name string `db:"name"`
Des sql.NullString `db:"des"`
UserCount int64 `db:"user_count"`
}
)
func newRoleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultRoleModel {
return &defaultRoleModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`role`",
}
}
func (m *defaultRoleModel) Delete(ctx context.Context, id string) error {
oaRoleIdKey := fmt.Sprintf("%s%v", cacheOaRoleIdPrefix, id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, oaRoleIdKey)
return err
}
func (m *defaultRoleModel) FindOne(ctx context.Context, id string) (*Role, error) {
oaRoleIdKey := fmt.Sprintf("%s%v", cacheOaRoleIdPrefix, id)
var resp Role
err := m.QueryRowCtx(ctx, &resp, oaRoleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", roleRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultRoleModel) Insert(ctx context.Context, data *Role) (sql.Result, error) {
oaRoleIdKey := fmt.Sprintf("%s%v", cacheOaRoleIdPrefix, data.Id)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, roleRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Id, data.Created, data.Updated, data.AppId, data.Name, data.Des, data.UserCount)
}, oaRoleIdKey)
return ret, err
}
func (m *defaultRoleModel) Update(ctx context.Context, data *Role) error {
oaRoleIdKey := fmt.Sprintf("%s%v", cacheOaRoleIdPrefix, data.Id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, roleRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.Name, data.Des, data.UserCount, data.Id)
}, oaRoleIdKey)
return err
}
func (m *defaultRoleModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheOaRoleIdPrefix, primary)
}
func (m *defaultRoleModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", roleRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultRoleModel) tableName() string {
return m.table
}

@ -0,0 +1,27 @@
package models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ UserModel = (*customUserModel)(nil)
type (
// UserModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserModel.
UserModel interface {
userModel
}
customUserModel struct {
*defaultUserModel
}
)
// NewUserModel returns a model for the database table.
func NewUserModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) UserModel {
return &customUserModel{
defaultUserModel: newUserModel(conn, c, opts...),
}
}

@ -0,0 +1,205 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
userFieldNames = builder.RawFieldNames(&User{})
userRows = strings.Join(userFieldNames, ",")
userRowsExpectAutoSet = strings.Join(stringx.Remove(userFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
userRowsWithPlaceHolder = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheOaUserIdPrefix = "cache:oa:user:id:"
cacheOaUserEmailPrefix = "cache:oa:user:email:"
cacheOaUserPhonePrefix = "cache:oa:user:phone:"
cacheOaUserUsernamePrefix = "cache:oa:user:username:"
)
type (
userModel interface {
Insert(ctx context.Context, data *User) (sql.Result, error)
FindOne(ctx context.Context, id string) (*User, error)
FindOneByEmail(ctx context.Context, email sql.NullString) (*User, error)
FindOneByPhone(ctx context.Context, phone sql.NullString) (*User, error)
FindOneByUsername(ctx context.Context, username string) (*User, error)
Update(ctx context.Context, data *User) error
Delete(ctx context.Context, id string) error
}
defaultUserModel struct {
sqlc.CachedConn
table string
}
User struct {
Id string `db:"id"` // User UUID
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
Username string `db:"username"`
Nickname sql.NullString `db:"nickname"`
Email sql.NullString `db:"email"`
Phone sql.NullString `db:"phone"`
Icon sql.NullString `db:"icon"`
RealCode sql.NullString `db:"_real_code"`
CheckCode sql.NullString `db:"_check_code"`
Status int64 `db:"status"` // 状态0ok1disabled
Used int64 `db:"used"`
Space int64 `db:"space"`
}
)
func newUserModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultUserModel {
return &defaultUserModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`user`",
}
}
func (m *defaultUserModel) Delete(ctx context.Context, id string) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
oaUserEmailKey := fmt.Sprintf("%s%v", cacheOaUserEmailPrefix, data.Email)
oaUserIdKey := fmt.Sprintf("%s%v", cacheOaUserIdPrefix, id)
oaUserPhoneKey := fmt.Sprintf("%s%v", cacheOaUserPhonePrefix, data.Phone)
oaUserUsernameKey := fmt.Sprintf("%s%v", cacheOaUserUsernamePrefix, data.Username)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, oaUserEmailKey, oaUserIdKey, oaUserPhoneKey, oaUserUsernameKey)
return err
}
func (m *defaultUserModel) FindOne(ctx context.Context, id string) (*User, error) {
oaUserIdKey := fmt.Sprintf("%s%v", cacheOaUserIdPrefix, id)
var resp User
err := m.QueryRowCtx(ctx, &resp, oaUserIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserModel) FindOneByEmail(ctx context.Context, email sql.NullString) (*User, error) {
oaUserEmailKey := fmt.Sprintf("%s%v", cacheOaUserEmailPrefix, email)
var resp User
err := m.QueryRowIndexCtx(ctx, &resp, oaUserEmailKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", userRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, email); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserModel) FindOneByPhone(ctx context.Context, phone sql.NullString) (*User, error) {
oaUserPhoneKey := fmt.Sprintf("%s%v", cacheOaUserPhonePrefix, phone)
var resp User
err := m.QueryRowIndexCtx(ctx, &resp, oaUserPhoneKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `phone` = ? limit 1", userRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, phone); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserModel) FindOneByUsername(ctx context.Context, username string) (*User, error) {
oaUserUsernameKey := fmt.Sprintf("%s%v", cacheOaUserUsernamePrefix, username)
var resp User
err := m.QueryRowIndexCtx(ctx, &resp, oaUserUsernameKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `username` = ? limit 1", userRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, username); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserModel) Insert(ctx context.Context, data *User) (sql.Result, error) {
oaUserEmailKey := fmt.Sprintf("%s%v", cacheOaUserEmailPrefix, data.Email)
oaUserIdKey := fmt.Sprintf("%s%v", cacheOaUserIdPrefix, data.Id)
oaUserPhoneKey := fmt.Sprintf("%s%v", cacheOaUserPhonePrefix, data.Phone)
oaUserUsernameKey := fmt.Sprintf("%s%v", cacheOaUserUsernamePrefix, data.Username)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, userRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Id, data.Created, data.Updated, data.Username, data.Nickname, data.Email, data.Phone, data.Icon, data.RealCode, data.CheckCode, data.Status, data.Used, data.Space)
}, oaUserEmailKey, oaUserIdKey, oaUserPhoneKey, oaUserUsernameKey)
return ret, err
}
func (m *defaultUserModel) Update(ctx context.Context, newData *User) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
oaUserEmailKey := fmt.Sprintf("%s%v", cacheOaUserEmailPrefix, data.Email)
oaUserIdKey := fmt.Sprintf("%s%v", cacheOaUserIdPrefix, data.Id)
oaUserPhoneKey := fmt.Sprintf("%s%v", cacheOaUserPhonePrefix, data.Phone)
oaUserUsernameKey := fmt.Sprintf("%s%v", cacheOaUserUsernamePrefix, data.Username)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.Username, newData.Nickname, newData.Email, newData.Phone, newData.Icon, newData.RealCode, newData.CheckCode, newData.Status, newData.Used, newData.Space, newData.Id)
}, oaUserEmailKey, oaUserIdKey, oaUserPhoneKey, oaUserUsernameKey)
return err
}
func (m *defaultUserModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheOaUserIdPrefix, primary)
}
func (m *defaultUserModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultUserModel) tableName() string {
return m.table
}

@ -0,0 +1,27 @@
package models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ UserRoleModel = (*customUserRoleModel)(nil)
type (
// UserRoleModel is an interface to be customized, add more methods here,
// and implement the added methods in customUserRoleModel.
UserRoleModel interface {
userRoleModel
}
customUserRoleModel struct {
*defaultUserRoleModel
}
)
// NewUserRoleModel returns a model for the database table.
func NewUserRoleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) UserRoleModel {
return &customUserRoleModel{
defaultUserRoleModel: newUserRoleModel(conn, c, opts...),
}
}

@ -0,0 +1,148 @@
// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
userRoleFieldNames = builder.RawFieldNames(&UserRole{})
userRoleRows = strings.Join(userRoleFieldNames, ",")
userRoleRowsExpectAutoSet = strings.Join(stringx.Remove(userRoleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
userRoleRowsWithPlaceHolder = strings.Join(stringx.Remove(userRoleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheOaUserRoleIdPrefix = "cache:oa:userRole:id:"
cacheOaUserRoleUserIdRoleIdPrefix = "cache:oa:userRole:userId:roleId:"
)
type (
userRoleModel interface {
Insert(ctx context.Context, data *UserRole) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*UserRole, error)
FindOneByUserIdRoleId(ctx context.Context, userId string, roleId string) (*UserRole, error)
Update(ctx context.Context, data *UserRole) error
Delete(ctx context.Context, id int64) error
}
defaultUserRoleModel struct {
sqlc.CachedConn
table string
}
UserRole struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
UserId string `db:"user_id"`
RoleId string `db:"role_id"`
Status string `db:"status"`
}
)
func newUserRoleModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultUserRoleModel {
return &defaultUserRoleModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`user_role`",
}
}
func (m *defaultUserRoleModel) Delete(ctx context.Context, id int64) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
oaUserRoleIdKey := fmt.Sprintf("%s%v", cacheOaUserRoleIdPrefix, id)
oaUserRoleUserIdRoleIdKey := fmt.Sprintf("%s%v:%v", cacheOaUserRoleUserIdRoleIdPrefix, data.UserId, data.RoleId)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, oaUserRoleIdKey, oaUserRoleUserIdRoleIdKey)
return err
}
func (m *defaultUserRoleModel) FindOne(ctx context.Context, id int64) (*UserRole, error) {
oaUserRoleIdKey := fmt.Sprintf("%s%v", cacheOaUserRoleIdPrefix, id)
var resp UserRole
err := m.QueryRowCtx(ctx, &resp, oaUserRoleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRoleRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserRoleModel) FindOneByUserIdRoleId(ctx context.Context, userId string, roleId string) (*UserRole, error) {
oaUserRoleUserIdRoleIdKey := fmt.Sprintf("%s%v:%v", cacheOaUserRoleUserIdRoleIdPrefix, userId, roleId)
var resp UserRole
err := m.QueryRowIndexCtx(ctx, &resp, oaUserRoleUserIdRoleIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `user_id` = ? and `role_id` = ? limit 1", userRoleRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, userId, roleId); err != nil {
return nil, err
}
return resp.Id, nil
}, m.queryPrimary)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserRoleModel) Insert(ctx context.Context, data *UserRole) (sql.Result, error) {
oaUserRoleIdKey := fmt.Sprintf("%s%v", cacheOaUserRoleIdPrefix, data.Id)
oaUserRoleUserIdRoleIdKey := fmt.Sprintf("%s%v:%v", cacheOaUserRoleUserIdRoleIdPrefix, data.UserId, data.RoleId)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, userRoleRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Created, data.Updated, data.UserId, data.RoleId, data.Status)
}, oaUserRoleIdKey, oaUserRoleUserIdRoleIdKey)
return ret, err
}
func (m *defaultUserRoleModel) Update(ctx context.Context, newData *UserRole) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
oaUserRoleIdKey := fmt.Sprintf("%s%v", cacheOaUserRoleIdPrefix, data.Id)
oaUserRoleUserIdRoleIdKey := fmt.Sprintf("%s%v:%v", cacheOaUserRoleUserIdRoleIdPrefix, data.UserId, data.RoleId)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userRoleRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.UserId, newData.RoleId, newData.Status, newData.Id)
}, oaUserRoleIdKey, oaUserRoleUserIdRoleIdKey)
return err
}
func (m *defaultUserRoleModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheOaUserRoleIdPrefix, primary)
}
func (m *defaultUserRoleModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", userRoleRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultUserRoleModel) tableName() string {
return m.table
}

@ -0,0 +1,5 @@
package models
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var ErrNotFound = sqlx.ErrNotFound

@ -0,0 +1,11 @@
syntax = "v1"
info (
title: "OA"
desc: "OA API"
author: "veypi"
email: "i@veypi.com"
)
import "user.api"
import "app.api"

@ -0,0 +1,39 @@
import "base.api"
type (
// 定义登录接口的请求体
AppReq {
error
appname string `json:"username"`
Password string `json:"password"`
}
// 定义登录接口的响应体
AppResp{
Id int64 `json:"id"`
Name string `json:"name"`
Token string `json:"token"`
ExpireAt string `json:"expireAt"`
}
)
@server (
// 代表当前 service 代码块下的路由生成代码时都会被放到 app 目录下
group: app
// 定义路由前缀为 "/v1"
prefix: /api/app
)
// 定义 HTTP 服务
// 微服务名称为 main生成的代码目录和配置文件将和 user 值相关
service main {
// 定义 http.HandleFunc 转换的 go 文件名称及方法
@handler Login
// 定义接口
// 请求方法为 post
// 路由为 /app/login
// 请求体为 LoginReq
// 响应体为 LoginResp响应体必须有 returns 关键字修饰
post /login (AppReq) returns (AppResp)
}

@ -0,0 +1,5 @@
type error {
status string `json:"status"`
code int `json:"code"`
}

@ -0,0 +1,39 @@
import "base.api"
type (
// 定义登录接口的请求体
LoginReq {
error
Username string `json:"username"`
Password string `json:"password"`
}
// 定义登录接口的响应体
LoginResp {
Id int64 `json:"id"`
Name string `json:"name"`
Token string `json:"token"`
ExpireAt string `json:"expireAt"`
}
)
@server (
// 代表当前 service 代码块下的路由生成代码时都会被放到 user 目录下
group: user
// 定义路由前缀为 "/v1"
prefix: /api/user
)
// 定义 HTTP 服务
// 微服务名称为main生成的代码目录和配置文件将和 user 值相关
service main {
// 定义 http.HandleFunc 转换的 go 文件名称及方法
@handler Login
// 定义接口
// 请求方法为 post
// 路由为 /user/login
// 请求体为 LoginReq
// 响应体为 LoginResp响应体必须有 returns 关键字修饰
post /login (LoginReq) returns (LoginResp)
}

@ -0,0 +1,150 @@
CREATE TABLE IF NOT EXISTS `user`
(
`id` varchar(32) NOT NULL DEFAULT '' COMMENT 'User UUID',
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`username` varchar(255) NOT NULL UNIQUE,
`nickname` varchar(255),
`email` varchar(255) UNIQUE,
`phone` varchar(255) UNIQUE,
`icon` varchar(255),
`_real_code` varchar(32),
`_check_code` binary(48),
`status` int NOT NULL COMMENT '状态0ok1disabled' DEFAULT 0,
`used` int NOT NULL DEFAULT 0,
`space` int NOT NULL DEFAULT 300,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `app`
(
`id` varchar(32) NOT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`_key` varchar(32) NOT NULL,
`name` varchar(255) NOT NULL,
`icon` varchar(255),
`des` TEXT,
`user_count` int NOT NULL DEFAULT 0,
`hide` tinyint(1) NOT NULL DEFAULT 0,
`join_method` int NOT NULL DEFAULT 0,
`role_id` varchar(32),
`host` varchar(255) NOT NULL DEFAULT '',
`redirect` varchar(255) NOT NULL DEFAULT '',
`status` int NOT NULL COMMENT '状态0ok1disabled' DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `app_user`
(
id int AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`app_id` varchar(32) NOT NULL,
`user_id` varchar(32) NOT NULL,
`status` int NOT NULL DEFAULT 0 COMMENT '0: ok,1:disabled,2:applying,3:deny',
PRIMARY KEY (`id`),
unique index (`user_id`,`app_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='app_to_user';
CREATE TABLE IF NOT EXISTS `role`
(
`id` varchar(32) NOT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`app_id` varchar(32) NOT NULL,
`name` varchar(255) NOT NULL,
`des` varchar(255),
`user_count` int NOT NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `user_role`
(
id int AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`user_id` varchar(32) NOT NULL,
`role_id` varchar(32) NOT NULL,
`status` varchar(32) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE INDEX (`user_id`,`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `resource`
(
id int AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`app_id` varchar(32) NOT NULL,
`name` varchar(32) NOT NULL,
`des` varchar(255),
PRIMARY KEY (`id`),
UNIQUE INDEX (`app_id`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `access`
(
`id` int NOT NULL AUTO_INCREMENT,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`app_id` varchar(32) NOT NULL,
`access_id` int NOT NULL DEFAULT 0,
`name` varchar(32) NOT NULL,
`role_id` varchar(32) NULL DEFAULT NULL,
`user_id` varchar(32) NULL DEFAULT NULL,
`rid` varchar(32) DEFAULT NULL COMMENT '资源子id',
`level` int NOT NULL DEFAULT 0,
-- PRIMARY KEY (`app_id`,`name`, `role_id`, `user_id`) USING BTREE,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `token`
(
`code` varchar(32) NOT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL,
`expired` datetime NOT NULL,
`client_id` varchar(32) NOT NULL,
`app_id` varchar(32) NOT NULL,
`user_id` varchar(32) NOT NULL,
`meta` json,
PRIMARY KEY (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `app` (`id`, `name`, `_key`, `role_id`)
VALUES ('FR9P5t8debxc11aFF', 'oa', 'AMpjwQHwVjGsb1WC4WG6', '1lytMwQL4uiNd0vsc');
INSERT INTO `resource` (`app_id`, `name`)
VALUES ('FR9P5t8debxc11aFF', 'app'),
('FR9P5t8debxc11aFF', 'user');
INSERT INTO `role` (`id`, `app_id`, `name`)
VALUES ('1lytMwQL4uiNd0vsc', 'FR9P5t8debxc11aFF', 'admin');
INSERT INTO `access` (`app_id`, `name`, `role_id`, `user_id`,`level`)
VALUES ('FR9P5t8debxc11aFF', 'app', '1lytMwQL4uiNd0vsc', NULL,5),
('FR9P5t8debxc11aFF', 'user', '1lytMwQL4uiNd0vsc', NULL,5);
Loading…
Cancel
Save