mirror of https://github.com/veypi/OneAuth.git
oa backend init with go zero
parent
0349640df7
commit
54a200f297
@ -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,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,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,5 @@
|
||||
|
||||
type error {
|
||||
status string `json:"status"`
|
||||
code int `json:"code"`
|
||||
}
|
Loading…
Reference in New Issue