chore: remove examples (#1871)
parent
1c37eff18a
commit
64bd619967
@ -1,21 +0,0 @@ |
||||
MIT License |
||||
|
||||
Copyright (c) 2021 Kratos |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE. |
@ -1,15 +0,0 @@ |
||||
# examples |
||||
|
||||
- examples/blog is simple crud project. |
||||
- examples/config is kratos config example. |
||||
- examples/errors is kratos errors example, it is generated through proto-gen-go-errors. |
||||
- examples/helloworld is helloworld example. |
||||
- examples/http is transport/http some examples of usage. |
||||
- examples/log is log example, including、logger、helper、filter、valuer, etc. |
||||
- examples/metadata is metadata example. |
||||
- examples/metrics is metrics example, in the example, prom is used to collect data. |
||||
- examples/registry is registration and discovery examples,including Etcd, Consul, Nacos. |
||||
- examples/traces is middleware/tracing example,middleware/tracing is implemented by opentelemetry. |
||||
- examples/validate is middleware/validate example, the verification code is generated by proto-gen-validate. |
||||
- examples/ws is implementation of transport interface with websocket example. |
||||
- examples/swagger is implementation of server with embed swagger api. |
@ -1,68 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"context" |
||||
"log" |
||||
|
||||
"github.com/go-kratos/kratos/examples/helloworld/helloworld" |
||||
"github.com/go-kratos/kratos/v2" |
||||
"github.com/go-kratos/kratos/v2/middleware/auth/jwt" |
||||
"github.com/go-kratos/kratos/v2/transport/grpc" |
||||
"github.com/go-kratos/kratos/v2/transport/http" |
||||
jwtv4 "github.com/golang-jwt/jwt/v4" |
||||
) |
||||
|
||||
type server struct { |
||||
helloworld.UnimplementedGreeterServer |
||||
|
||||
hc helloworld.GreeterClient |
||||
} |
||||
|
||||
func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { |
||||
return &helloworld.HelloReply{Message: "hello from service"}, nil |
||||
} |
||||
|
||||
func main() { |
||||
testKey := "testKey" |
||||
httpSrv := http.NewServer( |
||||
http.Address(":8000"), |
||||
http.Middleware( |
||||
jwt.Server(func(token *jwtv4.Token) (interface{}, error) { |
||||
return []byte(testKey), nil |
||||
}), |
||||
), |
||||
) |
||||
grpcSrv := grpc.NewServer( |
||||
grpc.Address(":9000"), |
||||
grpc.Middleware( |
||||
jwt.Server(func(token *jwtv4.Token) (interface{}, error) { |
||||
return []byte(testKey), nil |
||||
}), |
||||
), |
||||
) |
||||
serviceTestKey := "serviceTestKey" |
||||
con, _ := grpc.DialInsecure( |
||||
context.Background(), |
||||
grpc.WithEndpoint("dns:///127.0.0.1:9001"), |
||||
grpc.WithMiddleware( |
||||
jwt.Client(func(token *jwtv4.Token) (interface{}, error) { |
||||
return []byte(serviceTestKey), nil |
||||
}), |
||||
), |
||||
) |
||||
s := &server{ |
||||
hc: helloworld.NewGreeterClient(con), |
||||
} |
||||
helloworld.RegisterGreeterServer(grpcSrv, s) |
||||
helloworld.RegisterGreeterHTTPServer(httpSrv, s) |
||||
app := kratos.New( |
||||
kratos.Name("helloworld"), |
||||
kratos.Server( |
||||
httpSrv, |
||||
grpcSrv, |
||||
), |
||||
) |
||||
if err := app.Run(); err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
} |
@ -1,14 +0,0 @@ |
||||
|
||||
### Explain |
||||
This example is condensed by [go-web-framework-benchmark](https://github.com/smallnest/go-web-framework-benchmark) |
||||
|
||||
### Dependent |
||||
- wrk https://github.com/wg/wrk |
||||
- gnuplot http://www.gnuplot.info/ |
||||
|
||||
### Run |
||||
```bash |
||||
go build -o gowebbenchmark *.go |
||||
./test.sh |
||||
./testresults/plot.sh or plot_mac.sh |
||||
``` |
@ -1,3 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
web_frameworks=("kratos" "gin" "echo" "mux") |
@ -1,197 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"crypto/sha256" |
||||
"fmt" |
||||
"log" |
||||
"math/big" |
||||
http2 "net/http" |
||||
"os" |
||||
"runtime" |
||||
"strconv" |
||||
"time" |
||||
|
||||
"github.com/go-kratos/kratos/v2" |
||||
"github.com/go-kratos/kratos/v2/transport/http" |
||||
|
||||
"github.com/gin-gonic/gin" |
||||
"github.com/gorilla/mux" |
||||
"github.com/labstack/echo/v4" |
||||
) |
||||
|
||||
var ( |
||||
port = 8080 |
||||
sleepTime = 0 |
||||
cpuBound bool |
||||
target = 15 |
||||
sleepTimeDuration time.Duration |
||||
message = []byte("hello world") |
||||
samplingPoint = 20 // seconds
|
||||
) |
||||
|
||||
func main() { |
||||
args := os.Args |
||||
argsLen := len(args) |
||||
webFramework := "kratos" |
||||
if argsLen > 1 { |
||||
webFramework = args[1] |
||||
} |
||||
if argsLen > 2 { //nolint:gomnd
|
||||
sleepTime, _ = strconv.Atoi(args[2]) |
||||
if sleepTime == -1 { |
||||
cpuBound = true |
||||
sleepTime = 0 |
||||
} |
||||
} |
||||
if argsLen > 3 { //nolint:gomnd
|
||||
port, _ = strconv.Atoi(args[3]) |
||||
} |
||||
if argsLen > 4 { //nolint:gomnd
|
||||
samplingPoint, _ = strconv.Atoi(args[4]) |
||||
} |
||||
sleepTimeDuration = time.Duration(sleepTime) * time.Millisecond |
||||
samplingPointDuration := time.Duration(samplingPoint) * time.Second |
||||
|
||||
go func() { |
||||
time.Sleep(samplingPointDuration) |
||||
var mem runtime.MemStats |
||||
runtime.ReadMemStats(&mem) |
||||
var u uint64 = 1024 * 1024 |
||||
fmt.Printf("TotalAlloc: %d\n", mem.TotalAlloc/u) |
||||
fmt.Printf("Alloc: %d\n", mem.Alloc/u) |
||||
fmt.Printf("HeapAlloc: %d\n", mem.HeapAlloc/u) |
||||
fmt.Printf("HeapSys: %d\n", mem.HeapSys/u) |
||||
}() |
||||
|
||||
switch webFramework { |
||||
case "kratos": |
||||
KratosServer() |
||||
case "gin": |
||||
GinServer() |
||||
case "echo": |
||||
EchoServer() |
||||
case "mux": |
||||
MuxServer() |
||||
default: |
||||
fmt.Println("--------------------------------------------------------------------") |
||||
fmt.Println("------------- Unknown framework given!!! Check libs.sh -------------") |
||||
fmt.Println("------------- Unknown framework given!!! Check libs.sh -------------") |
||||
fmt.Println("------------- Unknown framework given!!! Check libs.sh -------------") |
||||
fmt.Println("--------------------------------------------------------------------") |
||||
} |
||||
} |
||||
|
||||
func KratosServer() { |
||||
httpSrv := http.NewServer( |
||||
http.Address(":" + strconv.Itoa(port)), |
||||
) |
||||
httpSrv.HandleFunc("/", kratosHandle) |
||||
app := kratos.New( |
||||
kratos.Name("benchmark"), |
||||
kratos.Server( |
||||
httpSrv, |
||||
), |
||||
) |
||||
|
||||
if err := app.Run(); err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
} |
||||
|
||||
func kratosHandle(w http2.ResponseWriter, q *http2.Request) { |
||||
if cpuBound { |
||||
pow(target) |
||||
} else { |
||||
if sleepTime > 0 { |
||||
time.Sleep(sleepTimeDuration) |
||||
} else { |
||||
runtime.Gosched() |
||||
} |
||||
} |
||||
_, _ = w.Write(message) |
||||
} |
||||
|
||||
func GinServer() { |
||||
gin.SetMode(gin.ReleaseMode) |
||||
mux := gin.New() |
||||
mux.GET("/", ginHandler) |
||||
_ = mux.Run(":" + strconv.Itoa(port)) |
||||
} |
||||
|
||||
func ginHandler(c *gin.Context) { |
||||
if cpuBound { |
||||
pow(target) |
||||
} else { |
||||
if sleepTime > 0 { |
||||
time.Sleep(sleepTimeDuration) |
||||
} else { |
||||
runtime.Gosched() |
||||
} |
||||
} |
||||
_, _ = c.Writer.Write(message) |
||||
} |
||||
|
||||
func EchoServer() { |
||||
e := echo.New() |
||||
e.GET("/", echoHandler) |
||||
_ = e.Start(":" + strconv.Itoa(port)) |
||||
} |
||||
|
||||
func echoHandler(c echo.Context) error { |
||||
if cpuBound { |
||||
pow(target) |
||||
} else { |
||||
if sleepTime > 0 { |
||||
time.Sleep(sleepTimeDuration) |
||||
} else { |
||||
runtime.Gosched() |
||||
} |
||||
} |
||||
_, _ = c.Response().Write(message) |
||||
return nil |
||||
} |
||||
|
||||
func MuxServer() { |
||||
r := mux.NewRouter() |
||||
r.HandleFunc("/", muxHandle) |
||||
http2.Handle("/", r) |
||||
_ = http2.ListenAndServe(":"+strconv.Itoa(port), r) |
||||
} |
||||
|
||||
func muxHandle(w http2.ResponseWriter, q *http2.Request) { |
||||
if cpuBound { |
||||
pow(target) |
||||
} else { |
||||
if sleepTime > 0 { |
||||
time.Sleep(sleepTimeDuration) |
||||
} else { |
||||
runtime.Gosched() |
||||
} |
||||
} |
||||
_, _ = w.Write(message) |
||||
} |
||||
|
||||
func pow(targetBits int) { |
||||
target := big.NewInt(1) |
||||
target.Lsh(target, uint(256-targetBits)) |
||||
|
||||
var hashInt big.Int |
||||
var hash [32]byte |
||||
nonce := 0 |
||||
|
||||
for { |
||||
data := "hello world " + strconv.Itoa(nonce) |
||||
hash = sha256.Sum256([]byte(data)) |
||||
hashInt.SetBytes(hash[:]) |
||||
|
||||
if hashInt.Cmp(target) == -1 { |
||||
break |
||||
} else { |
||||
nonce++ |
||||
} |
||||
|
||||
if nonce%100 == 0 { |
||||
runtime.Gosched() |
||||
} |
||||
} |
||||
} |
@ -1,86 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
server_bin_name="gowebbenchmark" |
||||
|
||||
. ./libs.sh |
||||
|
||||
length=${#web_frameworks[@]} |
||||
|
||||
test_result=() |
||||
|
||||
cpu_cores=`cat /proc/cpuinfo|grep processor|wc -l` |
||||
if [ $cpu_cores -eq 0 ] |
||||
then |
||||
cpu_cores=1 |
||||
fi |
||||
|
||||
test_web_framework() |
||||
{ |
||||
echo "testing web framework: $2" |
||||
./$server_bin_name $2 $3 & |
||||
sleep 2 |
||||
|
||||
throughput=`wrk -t$cpu_cores -c$4 -d30s http://127.0.0.1:8080/ | grep Requests/sec | awk '{print $2}'` |
||||
echo "throughput: $throughput requests/second" |
||||
test_result[$1]=$throughput |
||||
|
||||
pkill -9 $server_bin_name |
||||
sleep 2 |
||||
echo "finished testing $2" |
||||
echo |
||||
} |
||||
|
||||
test_all() |
||||
{ |
||||
echo "###################################" |
||||
echo " " |
||||
echo " ProcessingTime $1ms " |
||||
echo " Concurrency $2 " |
||||
echo " " |
||||
echo "###################################" |
||||
for ((i=0; i<$length; i++)) |
||||
do |
||||
test_web_framework $i ${web_frameworks[$i]} $1 $2 |
||||
done |
||||
} |
||||
|
||||
|
||||
pkill -9 $server_bin_name |
||||
|
||||
echo ","$(IFS=$','; echo "${web_frameworks[*]}" ) > processtime.csv |
||||
test_all 0 5000 |
||||
echo "0 ms,"$(IFS=$','; echo "${test_result[*]}" ) >> processtime.csv |
||||
test_all 10 5000 |
||||
echo "10 ms,"$(IFS=$','; echo "${test_result[*]}" ) >> processtime.csv |
||||
test_all 100 5000 |
||||
echo "100 ms,"$(IFS=$','; echo "${test_result[*]}" ) >> processtime.csv |
||||
test_all 500 5000 |
||||
echo "500 ms,"$(IFS=$','; echo "${test_result[*]}" ) >> processtime.csv |
||||
|
||||
|
||||
echo ","$(IFS=$','; echo "${web_frameworks[*]}" ) > concurrency.csv |
||||
test_all 30 100 |
||||
echo "100,"$(IFS=$','; echo "${test_result[*]}" ) >> concurrency.csv |
||||
test_all 30 1000 |
||||
echo "1000,"$(IFS=$','; echo "${test_result[*]}" ) >> concurrency.csv |
||||
test_all 30 5000 |
||||
echo "5000,"$(IFS=$','; echo "${test_result[*]}" ) >> concurrency.csv |
||||
|
||||
|
||||
test_all -1 5000 |
||||
echo ","$(IFS=$','; echo "${web_frameworks[*]}" ) > cpubound.csv |
||||
echo "cpu-bound,"$(IFS=$','; echo "${test_result[*]}" ) >> cpubound.csv |
||||
|
||||
echo ","$(IFS=$','; echo "${web_frameworks[*]}" ) > cpubound-concurrency.csv |
||||
test_all -1 100 |
||||
echo "100,"$(IFS=$','; echo "${test_result[*]}" ) >> cpubound-concurrency.csv |
||||
test_all -1 1000 |
||||
echo "1000,"$(IFS=$','; echo "${test_result[*]}" ) >> cpubound-concurrency.csv |
||||
test_all -1 5000 |
||||
echo "5000,"$(IFS=$','; echo "${test_result[*]}" ) >> cpubound-concurrency.csv |
||||
|
||||
|
||||
mv -f processtime.csv ./testresults |
||||
mv -f concurrency.csv ./testresults |
||||
mv -f cpubound.csv ./testresults |
||||
mv -f cpubound-concurrency.csv ./testresults |
@ -1,22 +0,0 @@ |
||||
reset |
||||
set title "Benchmark of different processing time" |
||||
set boxwidth 0.9 |
||||
set datafile separator "," |
||||
set style data histogram |
||||
set style histogram clustered gap 2 |
||||
set style fill solid 0.7 border |
||||
set border lw 0.8 |
||||
|
||||
set ylabel "requests / second" |
||||
set xtics nomirror rotate by -45 |
||||
set ytics nomirror |
||||
|
||||
set border 1+2 back |
||||
set boxwidth -2 |
||||
|
||||
set grid |
||||
|
||||
set term pngcairo font "Times Roman,14" enhanced size 1024,600 background rgb "gray80" |
||||
set output "../benchmark.png" |
||||
|
||||
plot 't_processtime.csv' using 2:xticlabels(1) title columnheader(2), '' using 3:xticlabels(1) title columnheader(3), '' using 4:xticlabels(1) title columnheader(4), '' using 5:xticlabels(1) title columnheader(5) |
@ -1,10 +0,0 @@ |
||||
#!/bin/bash |
||||
m_path=$(dirname $0) |
||||
m_path=${m_path/\./$(pwd)} |
||||
cd $m_path |
||||
|
||||
./transpose.sh |
||||
|
||||
gnuplot benchmark.gnu |
||||
|
||||
rm -fr t_*.csv |
@ -1,10 +0,0 @@ |
||||
#!/bin/bash |
||||
m_path=$(dirname $0) |
||||
m_path=${m_path/\./$(pwd)} |
||||
cd $m_path |
||||
|
||||
./transpose.sh |
||||
|
||||
gnuplot -c benchmark.gnu |
||||
|
||||
rm -fr t_*.csv |
@ -1,6 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
for file in `ls *.csv` |
||||
do |
||||
awk -f tst.awk $file > t_$file |
||||
done |
@ -1,15 +0,0 @@ |
||||
BEGIN { FS=OFS="," } |
||||
{ |
||||
for (rowNr=1;rowNr<=NF;rowNr++) { |
||||
cell[rowNr,NR] = $rowNr |
||||
} |
||||
maxRows = (NF > maxRows ? NF : maxRows) |
||||
maxCols = NR |
||||
} |
||||
END { |
||||
for (rowNr=1;rowNr<=maxRows;rowNr++) { |
||||
for (colNr=1;colNr<=maxCols;colNr++) { |
||||
printf "%s%s", cell[rowNr,colNr], (colNr < maxCols ? OFS : ORS) |
||||
} |
||||
} |
||||
} |
@ -1,36 +0,0 @@ |
||||
# Reference https://github.com/github/gitignore/blob/master/Go.gitignore |
||||
# Binaries for programs and plugins |
||||
*.exe |
||||
*.exe~ |
||||
*.dll |
||||
*.so |
||||
*.dylib |
||||
|
||||
# Test binary, built with `go test -c` |
||||
*.test |
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE |
||||
*.out |
||||
|
||||
# Dependency directories (remove the comment below to include it) |
||||
vendor/ |
||||
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects) |
||||
*.o |
||||
*.a |
||||
*.so |
||||
|
||||
# OS General |
||||
Thumbs.db |
||||
.DS_Store |
||||
|
||||
# project |
||||
*.cert |
||||
*.key |
||||
*.log |
||||
bin/ |
||||
|
||||
# Develop tools |
||||
.vscode/ |
||||
.idea/ |
||||
*.swp |
@ -1,21 +0,0 @@ |
||||
MIT License |
||||
|
||||
Copyright (c) 2020 go-kratos |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE. |
@ -1,106 +0,0 @@ |
||||
GOPATH:=$(shell go env GOPATH)
|
||||
VERSION=$(shell git describe --tags --always)
|
||||
INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
|
||||
API_PROTO_FILES=$(shell find api -name *.proto)
|
||||
KRATOS_VERSION=$(shell go mod graph |grep go-kratos/kratos/v2 |head -n 1 |awk -F '@' '{print $$2}')
|
||||
KRATOS=$(GOPATH)/pkg/mod/github.com/go-kratos/kratos/v2@$(KRATOS_VERSION)
|
||||
|
||||
.PHONY: init |
||||
# init env
|
||||
init: |
||||
go get -u github.com/go-kratos/kratos/cmd/kratos/v2
|
||||
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
|
||||
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
||||
go get -u github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2
|
||||
go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
|
||||
go get -u github.com/google/wire/cmd/wire
|
||||
|
||||
.PHONY: grpc |
||||
# generate grpc code
|
||||
grpc: |
||||
protoc --proto_path=. \
|
||||
--proto_path=$(KRATOS)/third_party \
|
||||
--go_out=paths=source_relative:. \
|
||||
--go-grpc_out=paths=source_relative:. \
|
||||
$(API_PROTO_FILES)
|
||||
|
||||
.PHONY: http |
||||
# generate http code
|
||||
http: |
||||
protoc --proto_path=. \
|
||||
--proto_path=$(KRATOS)/third_party \
|
||||
--go_out=paths=source_relative:. \
|
||||
--go-http_out=paths=source_relative:. \
|
||||
$(API_PROTO_FILES)
|
||||
|
||||
.PHONY: errors |
||||
# generate errors code
|
||||
errors: |
||||
protoc --proto_path=. \
|
||||
--proto_path=$(KRATOS)/third_party \
|
||||
--go_out=paths=source_relative:. \
|
||||
--go-errors_out=paths=source_relative:. \
|
||||
$(API_PROTO_FILES)
|
||||
|
||||
.PHONY: proto |
||||
# generate internal proto
|
||||
proto: |
||||
protoc --proto_path=. \
|
||||
--proto_path=$(KRATOS)/third_party \
|
||||
--go_out=paths=source_relative:. \
|
||||
$(INTERNAL_PROTO_FILES)
|
||||
|
||||
.PHONY: swagger |
||||
# generate swagger file
|
||||
swagger: |
||||
protoc --proto_path=. \
|
||||
--proto_path=$(KRATOS)/third_party \
|
||||
--openapiv2_out . \
|
||||
--openapiv2_opt logtostderr=true \
|
||||
$(API_PROTO_FILES)
|
||||
|
||||
.PHONY: generate |
||||
# generate client code
|
||||
generate: |
||||
go generate ./...
|
||||
|
||||
.PHONY: build |
||||
# build
|
||||
build: |
||||
mkdir -p bin/ && go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/ ./...
|
||||
|
||||
.PHONY: test |
||||
# test
|
||||
test: |
||||
go test -v ./... -cover
|
||||
|
||||
.PHONY: all |
||||
# generate all
|
||||
all: |
||||
make generate;
|
||||
make grpc;
|
||||
make http;
|
||||
make proto;
|
||||
make errors;
|
||||
make swagger;
|
||||
make build;
|
||||
make test;
|
||||
|
||||
# show help
|
||||
help: |
||||
@echo ''
|
||||
@echo 'Usage:'
|
||||
@echo ' make [target]'
|
||||
@echo ''
|
||||
@echo 'Targets:'
|
||||
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
|
||||
helpMessage = match(lastLine, /^# (.*)/); \
|
||||
if (helpMessage) { \
|
||||
helpCommand = substr($$1, 0, index($$1, ":")-1); \
|
||||
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
|
||||
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
|
||||
} \
|
||||
} \
|
||||
{ lastLine = $$0 }' $(MAKEFILE_LIST)
|
||||
|
||||
.DEFAULT_GOAL := help
|
@ -1,19 +0,0 @@ |
||||
# How to run this blog example server |
||||
1. You should ensure that your mysql server is running. |
||||
2. Ensure that the database named `testdb` has been created, |
||||
otherwise you should execute the following database script: |
||||
```mysql |
||||
create database testdb; |
||||
``` |
||||
3. Modify the `configs/config.yaml` file and add your mysql information in the data source: |
||||
```yaml |
||||
data: |
||||
database: |
||||
driver: mysql |
||||
source: root:password@tcp(127.0.0.1:3306)/testdb?parseTime=True |
||||
``` |
||||
4. Run your blog server: |
||||
```bash |
||||
$ go generate ./... |
||||
$ kratos run |
||||
``` |
@ -1,870 +0,0 @@ |
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.17.0
|
||||
// source: blog.proto
|
||||
|
||||
package v1 |
||||
|
||||
import ( |
||||
_ "github.com/envoyproxy/protoc-gen-validate/validate" |
||||
_ "google.golang.org/genproto/googleapis/api/annotations" |
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect" |
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl" |
||||
reflect "reflect" |
||||
sync "sync" |
||||
) |
||||
|
||||
const ( |
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) |
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) |
||||
) |
||||
|
||||
type Article struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` |
||||
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` |
||||
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` |
||||
Like int64 `protobuf:"varint,4,opt,name=like,proto3" json:"like,omitempty"` |
||||
} |
||||
|
||||
func (x *Article) Reset() { |
||||
*x = Article{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[0] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Article) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Article) ProtoMessage() {} |
||||
|
||||
func (x *Article) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[0] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Article.ProtoReflect.Descriptor instead.
|
||||
func (*Article) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{0} |
||||
} |
||||
|
||||
func (x *Article) GetId() int64 { |
||||
if x != nil { |
||||
return x.Id |
||||
} |
||||
return 0 |
||||
} |
||||
|
||||
func (x *Article) GetTitle() string { |
||||
if x != nil { |
||||
return x.Title |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Article) GetContent() string { |
||||
if x != nil { |
||||
return x.Content |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Article) GetLike() int64 { |
||||
if x != nil { |
||||
return x.Like |
||||
} |
||||
return 0 |
||||
} |
||||
|
||||
type CreateArticleRequest struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` // the title of string must be between 5 and 50 character
|
||||
Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"` |
||||
} |
||||
|
||||
func (x *CreateArticleRequest) Reset() { |
||||
*x = CreateArticleRequest{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[1] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *CreateArticleRequest) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*CreateArticleRequest) ProtoMessage() {} |
||||
|
||||
func (x *CreateArticleRequest) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[1] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use CreateArticleRequest.ProtoReflect.Descriptor instead.
|
||||
func (*CreateArticleRequest) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{1} |
||||
} |
||||
|
||||
func (x *CreateArticleRequest) GetTitle() string { |
||||
if x != nil { |
||||
return x.Title |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *CreateArticleRequest) GetContent() string { |
||||
if x != nil { |
||||
return x.Content |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
type CreateArticleReply struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Article *Article `protobuf:"bytes,1,opt,name=Article,proto3" json:"Article,omitempty"` |
||||
} |
||||
|
||||
func (x *CreateArticleReply) Reset() { |
||||
*x = CreateArticleReply{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[2] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *CreateArticleReply) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*CreateArticleReply) ProtoMessage() {} |
||||
|
||||
func (x *CreateArticleReply) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[2] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use CreateArticleReply.ProtoReflect.Descriptor instead.
|
||||
func (*CreateArticleReply) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{2} |
||||
} |
||||
|
||||
func (x *CreateArticleReply) GetArticle() *Article { |
||||
if x != nil { |
||||
return x.Article |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type UpdateArticleRequest struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` |
||||
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"` // the title of string must be between 5 and 50 character;
|
||||
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` |
||||
} |
||||
|
||||
func (x *UpdateArticleRequest) Reset() { |
||||
*x = UpdateArticleRequest{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[3] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *UpdateArticleRequest) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*UpdateArticleRequest) ProtoMessage() {} |
||||
|
||||
func (x *UpdateArticleRequest) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[3] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use UpdateArticleRequest.ProtoReflect.Descriptor instead.
|
||||
func (*UpdateArticleRequest) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{3} |
||||
} |
||||
|
||||
func (x *UpdateArticleRequest) GetId() int64 { |
||||
if x != nil { |
||||
return x.Id |
||||
} |
||||
return 0 |
||||
} |
||||
|
||||
func (x *UpdateArticleRequest) GetTitle() string { |
||||
if x != nil { |
||||
return x.Title |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *UpdateArticleRequest) GetContent() string { |
||||
if x != nil { |
||||
return x.Content |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
type UpdateArticleReply struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Article *Article `protobuf:"bytes,1,opt,name=Article,proto3" json:"Article,omitempty"` |
||||
} |
||||
|
||||
func (x *UpdateArticleReply) Reset() { |
||||
*x = UpdateArticleReply{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[4] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *UpdateArticleReply) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*UpdateArticleReply) ProtoMessage() {} |
||||
|
||||
func (x *UpdateArticleReply) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[4] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use UpdateArticleReply.ProtoReflect.Descriptor instead.
|
||||
func (*UpdateArticleReply) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{4} |
||||
} |
||||
|
||||
func (x *UpdateArticleReply) GetArticle() *Article { |
||||
if x != nil { |
||||
return x.Article |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type DeleteArticleRequest struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` |
||||
} |
||||
|
||||
func (x *DeleteArticleRequest) Reset() { |
||||
*x = DeleteArticleRequest{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[5] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *DeleteArticleRequest) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*DeleteArticleRequest) ProtoMessage() {} |
||||
|
||||
func (x *DeleteArticleRequest) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[5] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use DeleteArticleRequest.ProtoReflect.Descriptor instead.
|
||||
func (*DeleteArticleRequest) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{5} |
||||
} |
||||
|
||||
func (x *DeleteArticleRequest) GetId() int64 { |
||||
if x != nil { |
||||
return x.Id |
||||
} |
||||
return 0 |
||||
} |
||||
|
||||
type DeleteArticleReply struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
} |
||||
|
||||
func (x *DeleteArticleReply) Reset() { |
||||
*x = DeleteArticleReply{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[6] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *DeleteArticleReply) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*DeleteArticleReply) ProtoMessage() {} |
||||
|
||||
func (x *DeleteArticleReply) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[6] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use DeleteArticleReply.ProtoReflect.Descriptor instead.
|
||||
func (*DeleteArticleReply) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{6} |
||||
} |
||||
|
||||
type GetArticleRequest struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` |
||||
} |
||||
|
||||
func (x *GetArticleRequest) Reset() { |
||||
*x = GetArticleRequest{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[7] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *GetArticleRequest) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*GetArticleRequest) ProtoMessage() {} |
||||
|
||||
func (x *GetArticleRequest) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[7] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use GetArticleRequest.ProtoReflect.Descriptor instead.
|
||||
func (*GetArticleRequest) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{7} |
||||
} |
||||
|
||||
func (x *GetArticleRequest) GetId() int64 { |
||||
if x != nil { |
||||
return x.Id |
||||
} |
||||
return 0 |
||||
} |
||||
|
||||
type GetArticleReply struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Article *Article `protobuf:"bytes,1,opt,name=Article,proto3" json:"Article,omitempty"` |
||||
} |
||||
|
||||
func (x *GetArticleReply) Reset() { |
||||
*x = GetArticleReply{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[8] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *GetArticleReply) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*GetArticleReply) ProtoMessage() {} |
||||
|
||||
func (x *GetArticleReply) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[8] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use GetArticleReply.ProtoReflect.Descriptor instead.
|
||||
func (*GetArticleReply) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{8} |
||||
} |
||||
|
||||
func (x *GetArticleReply) GetArticle() *Article { |
||||
if x != nil { |
||||
return x.Article |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type ListArticleRequest struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
} |
||||
|
||||
func (x *ListArticleRequest) Reset() { |
||||
*x = ListArticleRequest{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[9] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *ListArticleRequest) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*ListArticleRequest) ProtoMessage() {} |
||||
|
||||
func (x *ListArticleRequest) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[9] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use ListArticleRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ListArticleRequest) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{9} |
||||
} |
||||
|
||||
type ListArticleReply struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Results []*Article `protobuf:"bytes,1,rep,name=results,proto3" json:"results,omitempty"` |
||||
} |
||||
|
||||
func (x *ListArticleReply) Reset() { |
||||
*x = ListArticleReply{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_blog_proto_msgTypes[10] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *ListArticleReply) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*ListArticleReply) ProtoMessage() {} |
||||
|
||||
func (x *ListArticleReply) ProtoReflect() protoreflect.Message { |
||||
mi := &file_blog_proto_msgTypes[10] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use ListArticleReply.ProtoReflect.Descriptor instead.
|
||||
func (*ListArticleReply) Descriptor() ([]byte, []int) { |
||||
return file_blog_proto_rawDescGZIP(), []int{10} |
||||
} |
||||
|
||||
func (x *ListArticleReply) GetResults() []*Article { |
||||
if x != nil { |
||||
return x.Results |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
var File_blog_proto protoreflect.FileDescriptor |
||||
|
||||
var file_blog_proto_rawDesc = []byte{ |
||||
0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x62, 0x6c, |
||||
0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, |
||||
0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
||||
0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, |
||||
0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, |
||||
0x22, 0x5d, 0x0a, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, |
||||
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, |
||||
0x69, 0x74, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, |
||||
0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, |
||||
0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6c, |
||||
0x69, 0x6b, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x6c, 0x69, 0x6b, 0x65, 0x22, |
||||
0x51, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, |
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, |
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04, 0x10, 0x05, 0x18, |
||||
0x32, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, |
||||
0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, |
||||
0x6e, 0x74, 0x22, 0x44, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, |
||||
0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x72, 0x74, 0x69, |
||||
0x63, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x62, 0x6c, 0x6f, 0x67, |
||||
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, |
||||
0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x22, 0x6a, 0x0a, 0x14, 0x55, 0x70, 0x64, 0x61, |
||||
0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, |
||||
0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, |
||||
0x04, 0x22, 0x02, 0x20, 0x00, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x74, 0x69, 0x74, |
||||
0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04, 0x10, |
||||
0x05, 0x18, 0x32, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, |
||||
0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, |
||||
0x74, 0x65, 0x6e, 0x74, 0x22, 0x44, 0x0a, 0x12, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x72, |
||||
0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2e, 0x0a, 0x07, 0x41, 0x72, |
||||
0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x62, 0x6c, |
||||
0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, |
||||
0x65, 0x52, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x22, 0x26, 0x0a, 0x14, 0x44, 0x65, |
||||
0x6c, 0x65, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, |
||||
0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, |
||||
0x69, 0x64, 0x22, 0x14, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, |
||||
0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x23, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x41, |
||||
0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, |
||||
0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x41, 0x0a, |
||||
0x0f, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, |
||||
0x12, 0x2e, 0x0a, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, |
||||
0x0b, 0x32, 0x14, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, |
||||
0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, |
||||
0x22, 0x14, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, |
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x42, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x72, |
||||
0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2e, 0x0a, 0x07, 0x72, 0x65, |
||||
0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x62, 0x6c, |
||||
0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, |
||||
0x65, 0x52, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x32, 0xa7, 0x04, 0x0a, 0x0b, 0x42, |
||||
0x6c, 0x6f, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x0d, 0x43, 0x72, |
||||
0x65, 0x61, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x21, 0x2e, 0x62, 0x6c, |
||||
0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, |
||||
0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, |
||||
0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, |
||||
0x61, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, |
||||
0x17, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11, 0x22, 0x0c, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, |
||||
0x69, 0x63, 0x6c, 0x65, 0x2f, 0x3a, 0x01, 0x2a, 0x12, 0x70, 0x0a, 0x0d, 0x55, 0x70, 0x64, 0x61, |
||||
0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x21, 0x2e, 0x62, 0x6c, 0x6f, 0x67, |
||||
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x72, |
||||
0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x62, |
||||
0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, |
||||
0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x1b, 0x82, |
||||
0xd3, 0xe4, 0x93, 0x02, 0x15, 0x1a, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, 0x69, 0x63, |
||||
0x6c, 0x65, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x3a, 0x01, 0x2a, 0x12, 0x6d, 0x0a, 0x0d, 0x44, 0x65, |
||||
0x6c, 0x65, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x21, 0x2e, 0x62, 0x6c, |
||||
0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, |
||||
0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, |
||||
0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, |
||||
0x65, 0x74, 0x65, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, |
||||
0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x2a, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, |
||||
0x69, 0x63, 0x6c, 0x65, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x64, 0x0a, 0x0a, 0x47, 0x65, 0x74, |
||||
0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x1e, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, |
||||
0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, |
||||
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, |
||||
0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, |
||||
0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, |
||||
0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, |
||||
0x63, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x1f, |
||||
0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, |
||||
0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, |
||||
0x1d, 0x2e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, |
||||
0x73, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x14, |
||||
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x12, 0x0c, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x72, 0x74, 0x69, |
||||
0x63, 0x6c, 0x65, 0x2f, 0x42, 0x44, 0x0a, 0x0b, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x61, 0x70, 0x69, |
||||
0x2e, 0x76, 0x31, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, |
||||
0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, |
||||
0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x62, 0x6c, 0x6f, 0x67, |
||||
0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, |
||||
0x6f, 0x33, |
||||
} |
||||
|
||||
var ( |
||||
file_blog_proto_rawDescOnce sync.Once |
||||
file_blog_proto_rawDescData = file_blog_proto_rawDesc |
||||
) |
||||
|
||||
func file_blog_proto_rawDescGZIP() []byte { |
||||
file_blog_proto_rawDescOnce.Do(func() { |
||||
file_blog_proto_rawDescData = protoimpl.X.CompressGZIP(file_blog_proto_rawDescData) |
||||
}) |
||||
return file_blog_proto_rawDescData |
||||
} |
||||
|
||||
var file_blog_proto_msgTypes = make([]protoimpl.MessageInfo, 11) |
||||
var file_blog_proto_goTypes = []interface{}{ |
||||
(*Article)(nil), // 0: blog.api.v1.Article
|
||||
(*CreateArticleRequest)(nil), // 1: blog.api.v1.CreateArticleRequest
|
||||
(*CreateArticleReply)(nil), // 2: blog.api.v1.CreateArticleReply
|
||||
(*UpdateArticleRequest)(nil), // 3: blog.api.v1.UpdateArticleRequest
|
||||
(*UpdateArticleReply)(nil), // 4: blog.api.v1.UpdateArticleReply
|
||||
(*DeleteArticleRequest)(nil), // 5: blog.api.v1.DeleteArticleRequest
|
||||
(*DeleteArticleReply)(nil), // 6: blog.api.v1.DeleteArticleReply
|
||||
(*GetArticleRequest)(nil), // 7: blog.api.v1.GetArticleRequest
|
||||
(*GetArticleReply)(nil), // 8: blog.api.v1.GetArticleReply
|
||||
(*ListArticleRequest)(nil), // 9: blog.api.v1.ListArticleRequest
|
||||
(*ListArticleReply)(nil), // 10: blog.api.v1.ListArticleReply
|
||||
} |
||||
var file_blog_proto_depIdxs = []int32{ |
||||
0, // 0: blog.api.v1.CreateArticleReply.Article:type_name -> blog.api.v1.Article
|
||||
0, // 1: blog.api.v1.UpdateArticleReply.Article:type_name -> blog.api.v1.Article
|
||||
0, // 2: blog.api.v1.GetArticleReply.Article:type_name -> blog.api.v1.Article
|
||||
0, // 3: blog.api.v1.ListArticleReply.results:type_name -> blog.api.v1.Article
|
||||
1, // 4: blog.api.v1.BlogService.CreateArticle:input_type -> blog.api.v1.CreateArticleRequest
|
||||
3, // 5: blog.api.v1.BlogService.UpdateArticle:input_type -> blog.api.v1.UpdateArticleRequest
|
||||
5, // 6: blog.api.v1.BlogService.DeleteArticle:input_type -> blog.api.v1.DeleteArticleRequest
|
||||
7, // 7: blog.api.v1.BlogService.GetArticle:input_type -> blog.api.v1.GetArticleRequest
|
||||
9, // 8: blog.api.v1.BlogService.ListArticle:input_type -> blog.api.v1.ListArticleRequest
|
||||
2, // 9: blog.api.v1.BlogService.CreateArticle:output_type -> blog.api.v1.CreateArticleReply
|
||||
4, // 10: blog.api.v1.BlogService.UpdateArticle:output_type -> blog.api.v1.UpdateArticleReply
|
||||
6, // 11: blog.api.v1.BlogService.DeleteArticle:output_type -> blog.api.v1.DeleteArticleReply
|
||||
8, // 12: blog.api.v1.BlogService.GetArticle:output_type -> blog.api.v1.GetArticleReply
|
||||
10, // 13: blog.api.v1.BlogService.ListArticle:output_type -> blog.api.v1.ListArticleReply
|
||||
9, // [9:14] is the sub-list for method output_type
|
||||
4, // [4:9] is the sub-list for method input_type
|
||||
4, // [4:4] is the sub-list for extension type_name
|
||||
4, // [4:4] is the sub-list for extension extendee
|
||||
0, // [0:4] is the sub-list for field type_name
|
||||
} |
||||
|
||||
func init() { file_blog_proto_init() } |
||||
func file_blog_proto_init() { |
||||
if File_blog_proto != nil { |
||||
return |
||||
} |
||||
if !protoimpl.UnsafeEnabled { |
||||
file_blog_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Article); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*CreateArticleRequest); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*CreateArticleReply); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*UpdateArticleRequest); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*UpdateArticleReply); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*DeleteArticleRequest); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*DeleteArticleReply); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*GetArticleRequest); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*GetArticleReply); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*ListArticleRequest); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_blog_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*ListArticleReply); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
} |
||||
type x struct{} |
||||
out := protoimpl.TypeBuilder{ |
||||
File: protoimpl.DescBuilder{ |
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), |
||||
RawDescriptor: file_blog_proto_rawDesc, |
||||
NumEnums: 0, |
||||
NumMessages: 11, |
||||
NumExtensions: 0, |
||||
NumServices: 1, |
||||
}, |
||||
GoTypes: file_blog_proto_goTypes, |
||||
DependencyIndexes: file_blog_proto_depIdxs, |
||||
MessageInfos: file_blog_proto_msgTypes, |
||||
}.Build() |
||||
File_blog_proto = out.File |
||||
file_blog_proto_rawDesc = nil |
||||
file_blog_proto_goTypes = nil |
||||
file_blog_proto_depIdxs = nil |
||||
} |
@ -1,846 +0,0 @@ |
||||
// Code generated by protoc-gen-validate. DO NOT EDIT.
|
||||
// source: blog.proto
|
||||
|
||||
package v1 |
||||
|
||||
import ( |
||||
"bytes" |
||||
"errors" |
||||
"fmt" |
||||
"net" |
||||
"net/mail" |
||||
"net/url" |
||||
"regexp" |
||||
"strings" |
||||
"time" |
||||
"unicode/utf8" |
||||
|
||||
"google.golang.org/protobuf/types/known/anypb" |
||||
) |
||||
|
||||
// ensure the imports are used
|
||||
var ( |
||||
_ = bytes.MinRead |
||||
_ = errors.New("") |
||||
_ = fmt.Print |
||||
_ = utf8.UTFMax |
||||
_ = (*regexp.Regexp)(nil) |
||||
_ = (*strings.Reader)(nil) |
||||
_ = net.IPv4len |
||||
_ = time.Duration(0) |
||||
_ = (*url.URL)(nil) |
||||
_ = (*mail.Address)(nil) |
||||
_ = anypb.Any{} |
||||
) |
||||
|
||||
// Validate checks the field values on Article with the rules defined in the
|
||||
// proto definition for this message. If any rules are violated, an error is returned.
|
||||
func (m *Article) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
// no validation rules for Id
|
||||
|
||||
// no validation rules for Title
|
||||
|
||||
// no validation rules for Content
|
||||
|
||||
// no validation rules for Like
|
||||
|
||||
return nil |
||||
} |
||||
|
||||
// ArticleValidationError is the validation error returned by Article.Validate
|
||||
// if the designated constraints aren't met.
|
||||
type ArticleValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e ArticleValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e ArticleValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e ArticleValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e ArticleValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e ArticleValidationError) ErrorName() string { return "ArticleValidationError" } |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e ArticleValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sArticle.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = ArticleValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = ArticleValidationError{} |
||||
|
||||
// Validate checks the field values on CreateArticleRequest with the rules
|
||||
// defined in the proto definition for this message. If any rules are
|
||||
// violated, an error is returned.
|
||||
func (m *CreateArticleRequest) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
if l := utf8.RuneCountInString(m.GetTitle()); l < 5 || l > 50 { |
||||
return CreateArticleRequestValidationError{ |
||||
field: "Title", |
||||
reason: "value length must be between 5 and 50 runes, inclusive", |
||||
} |
||||
} |
||||
|
||||
// no validation rules for Content
|
||||
|
||||
return nil |
||||
} |
||||
|
||||
// CreateArticleRequestValidationError is the validation error returned by
|
||||
// CreateArticleRequest.Validate if the designated constraints aren't met.
|
||||
type CreateArticleRequestValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e CreateArticleRequestValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e CreateArticleRequestValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e CreateArticleRequestValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e CreateArticleRequestValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e CreateArticleRequestValidationError) ErrorName() string { |
||||
return "CreateArticleRequestValidationError" |
||||
} |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e CreateArticleRequestValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sCreateArticleRequest.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = CreateArticleRequestValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = CreateArticleRequestValidationError{} |
||||
|
||||
// Validate checks the field values on CreateArticleReply with the rules
|
||||
// defined in the proto definition for this message. If any rules are
|
||||
// violated, an error is returned.
|
||||
func (m *CreateArticleReply) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
if v, ok := interface{}(m.GetArticle()).(interface{ Validate() error }); ok { |
||||
if err := v.Validate(); err != nil { |
||||
return CreateArticleReplyValidationError{ |
||||
field: "Article", |
||||
reason: "embedded message failed validation", |
||||
cause: err, |
||||
} |
||||
} |
||||
} |
||||
|
||||
return nil |
||||
} |
||||
|
||||
// CreateArticleReplyValidationError is the validation error returned by
|
||||
// CreateArticleReply.Validate if the designated constraints aren't met.
|
||||
type CreateArticleReplyValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e CreateArticleReplyValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e CreateArticleReplyValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e CreateArticleReplyValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e CreateArticleReplyValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e CreateArticleReplyValidationError) ErrorName() string { |
||||
return "CreateArticleReplyValidationError" |
||||
} |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e CreateArticleReplyValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sCreateArticleReply.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = CreateArticleReplyValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = CreateArticleReplyValidationError{} |
||||
|
||||
// Validate checks the field values on UpdateArticleRequest with the rules
|
||||
// defined in the proto definition for this message. If any rules are
|
||||
// violated, an error is returned.
|
||||
func (m *UpdateArticleRequest) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
if m.GetId() <= 0 { |
||||
return UpdateArticleRequestValidationError{ |
||||
field: "Id", |
||||
reason: "value must be greater than 0", |
||||
} |
||||
} |
||||
|
||||
if l := utf8.RuneCountInString(m.GetTitle()); l < 5 || l > 50 { |
||||
return UpdateArticleRequestValidationError{ |
||||
field: "Title", |
||||
reason: "value length must be between 5 and 50 runes, inclusive", |
||||
} |
||||
} |
||||
|
||||
// no validation rules for Content
|
||||
|
||||
return nil |
||||
} |
||||
|
||||
// UpdateArticleRequestValidationError is the validation error returned by
|
||||
// UpdateArticleRequest.Validate if the designated constraints aren't met.
|
||||
type UpdateArticleRequestValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e UpdateArticleRequestValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e UpdateArticleRequestValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e UpdateArticleRequestValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e UpdateArticleRequestValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e UpdateArticleRequestValidationError) ErrorName() string { |
||||
return "UpdateArticleRequestValidationError" |
||||
} |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e UpdateArticleRequestValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sUpdateArticleRequest.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = UpdateArticleRequestValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = UpdateArticleRequestValidationError{} |
||||
|
||||
// Validate checks the field values on UpdateArticleReply with the rules
|
||||
// defined in the proto definition for this message. If any rules are
|
||||
// violated, an error is returned.
|
||||
func (m *UpdateArticleReply) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
if v, ok := interface{}(m.GetArticle()).(interface{ Validate() error }); ok { |
||||
if err := v.Validate(); err != nil { |
||||
return UpdateArticleReplyValidationError{ |
||||
field: "Article", |
||||
reason: "embedded message failed validation", |
||||
cause: err, |
||||
} |
||||
} |
||||
} |
||||
|
||||
return nil |
||||
} |
||||
|
||||
// UpdateArticleReplyValidationError is the validation error returned by
|
||||
// UpdateArticleReply.Validate if the designated constraints aren't met.
|
||||
type UpdateArticleReplyValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e UpdateArticleReplyValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e UpdateArticleReplyValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e UpdateArticleReplyValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e UpdateArticleReplyValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e UpdateArticleReplyValidationError) ErrorName() string { |
||||
return "UpdateArticleReplyValidationError" |
||||
} |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e UpdateArticleReplyValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sUpdateArticleReply.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = UpdateArticleReplyValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = UpdateArticleReplyValidationError{} |
||||
|
||||
// Validate checks the field values on DeleteArticleRequest with the rules
|
||||
// defined in the proto definition for this message. If any rules are
|
||||
// violated, an error is returned.
|
||||
func (m *DeleteArticleRequest) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
// no validation rules for Id
|
||||
|
||||
return nil |
||||
} |
||||
|
||||
// DeleteArticleRequestValidationError is the validation error returned by
|
||||
// DeleteArticleRequest.Validate if the designated constraints aren't met.
|
||||
type DeleteArticleRequestValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e DeleteArticleRequestValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e DeleteArticleRequestValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e DeleteArticleRequestValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e DeleteArticleRequestValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e DeleteArticleRequestValidationError) ErrorName() string { |
||||
return "DeleteArticleRequestValidationError" |
||||
} |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e DeleteArticleRequestValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sDeleteArticleRequest.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = DeleteArticleRequestValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = DeleteArticleRequestValidationError{} |
||||
|
||||
// Validate checks the field values on DeleteArticleReply with the rules
|
||||
// defined in the proto definition for this message. If any rules are
|
||||
// violated, an error is returned.
|
||||
func (m *DeleteArticleReply) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
return nil |
||||
} |
||||
|
||||
// DeleteArticleReplyValidationError is the validation error returned by
|
||||
// DeleteArticleReply.Validate if the designated constraints aren't met.
|
||||
type DeleteArticleReplyValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e DeleteArticleReplyValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e DeleteArticleReplyValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e DeleteArticleReplyValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e DeleteArticleReplyValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e DeleteArticleReplyValidationError) ErrorName() string { |
||||
return "DeleteArticleReplyValidationError" |
||||
} |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e DeleteArticleReplyValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sDeleteArticleReply.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = DeleteArticleReplyValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = DeleteArticleReplyValidationError{} |
||||
|
||||
// Validate checks the field values on GetArticleRequest with the rules defined
|
||||
// in the proto definition for this message. If any rules are violated, an
|
||||
// error is returned.
|
||||
func (m *GetArticleRequest) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
// no validation rules for Id
|
||||
|
||||
return nil |
||||
} |
||||
|
||||
// GetArticleRequestValidationError is the validation error returned by
|
||||
// GetArticleRequest.Validate if the designated constraints aren't met.
|
||||
type GetArticleRequestValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e GetArticleRequestValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e GetArticleRequestValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e GetArticleRequestValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e GetArticleRequestValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e GetArticleRequestValidationError) ErrorName() string { |
||||
return "GetArticleRequestValidationError" |
||||
} |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e GetArticleRequestValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sGetArticleRequest.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = GetArticleRequestValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = GetArticleRequestValidationError{} |
||||
|
||||
// Validate checks the field values on GetArticleReply with the rules defined
|
||||
// in the proto definition for this message. If any rules are violated, an
|
||||
// error is returned.
|
||||
func (m *GetArticleReply) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
if v, ok := interface{}(m.GetArticle()).(interface{ Validate() error }); ok { |
||||
if err := v.Validate(); err != nil { |
||||
return GetArticleReplyValidationError{ |
||||
field: "Article", |
||||
reason: "embedded message failed validation", |
||||
cause: err, |
||||
} |
||||
} |
||||
} |
||||
|
||||
return nil |
||||
} |
||||
|
||||
// GetArticleReplyValidationError is the validation error returned by
|
||||
// GetArticleReply.Validate if the designated constraints aren't met.
|
||||
type GetArticleReplyValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e GetArticleReplyValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e GetArticleReplyValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e GetArticleReplyValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e GetArticleReplyValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e GetArticleReplyValidationError) ErrorName() string { return "GetArticleReplyValidationError" } |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e GetArticleReplyValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sGetArticleReply.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = GetArticleReplyValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = GetArticleReplyValidationError{} |
||||
|
||||
// Validate checks the field values on ListArticleRequest with the rules
|
||||
// defined in the proto definition for this message. If any rules are
|
||||
// violated, an error is returned.
|
||||
func (m *ListArticleRequest) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
return nil |
||||
} |
||||
|
||||
// ListArticleRequestValidationError is the validation error returned by
|
||||
// ListArticleRequest.Validate if the designated constraints aren't met.
|
||||
type ListArticleRequestValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e ListArticleRequestValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e ListArticleRequestValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e ListArticleRequestValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e ListArticleRequestValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e ListArticleRequestValidationError) ErrorName() string { |
||||
return "ListArticleRequestValidationError" |
||||
} |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e ListArticleRequestValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sListArticleRequest.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = ListArticleRequestValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = ListArticleRequestValidationError{} |
||||
|
||||
// Validate checks the field values on ListArticleReply with the rules defined
|
||||
// in the proto definition for this message. If any rules are violated, an
|
||||
// error is returned.
|
||||
func (m *ListArticleReply) Validate() error { |
||||
if m == nil { |
||||
return nil |
||||
} |
||||
|
||||
for idx, item := range m.GetResults() { |
||||
_, _ = idx, item |
||||
|
||||
if v, ok := interface{}(item).(interface{ Validate() error }); ok { |
||||
if err := v.Validate(); err != nil { |
||||
return ListArticleReplyValidationError{ |
||||
field: fmt.Sprintf("Results[%v]", idx), |
||||
reason: "embedded message failed validation", |
||||
cause: err, |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
return nil |
||||
} |
||||
|
||||
// ListArticleReplyValidationError is the validation error returned by
|
||||
// ListArticleReply.Validate if the designated constraints aren't met.
|
||||
type ListArticleReplyValidationError struct { |
||||
field string |
||||
reason string |
||||
cause error |
||||
key bool |
||||
} |
||||
|
||||
// Field function returns field value.
|
||||
func (e ListArticleReplyValidationError) Field() string { return e.field } |
||||
|
||||
// Reason function returns reason value.
|
||||
func (e ListArticleReplyValidationError) Reason() string { return e.reason } |
||||
|
||||
// Cause function returns cause value.
|
||||
func (e ListArticleReplyValidationError) Cause() error { return e.cause } |
||||
|
||||
// Key function returns key value.
|
||||
func (e ListArticleReplyValidationError) Key() bool { return e.key } |
||||
|
||||
// ErrorName returns error name.
|
||||
func (e ListArticleReplyValidationError) ErrorName() string { return "ListArticleReplyValidationError" } |
||||
|
||||
// Error satisfies the builtin error interface
|
||||
func (e ListArticleReplyValidationError) Error() string { |
||||
cause := "" |
||||
if e.cause != nil { |
||||
cause = fmt.Sprintf(" | caused by: %v", e.cause) |
||||
} |
||||
|
||||
key := "" |
||||
if e.key { |
||||
key = "key for " |
||||
} |
||||
|
||||
return fmt.Sprintf( |
||||
"invalid %sListArticleReply.%s: %s%s", |
||||
key, |
||||
e.field, |
||||
e.reason, |
||||
cause) |
||||
} |
||||
|
||||
var _ error = ListArticleReplyValidationError{} |
||||
|
||||
var _ interface { |
||||
Field() string |
||||
Reason() string |
||||
Key() bool |
||||
Cause() error |
||||
ErrorName() string |
||||
} = ListArticleReplyValidationError{} |
@ -1,89 +0,0 @@ |
||||
syntax = "proto3"; |
||||
|
||||
package blog.api.v1; |
||||
|
||||
option go_package = "github.com/go-kratos/kratos/examples/blog/api/v1;v1"; |
||||
option java_multiple_files = true; |
||||
option java_package = "blog.api.v1"; |
||||
|
||||
import "google/api/annotations.proto"; |
||||
// the validate rules: |
||||
// https://github.com/envoyproxy/protoc-gen-validate |
||||
import "validate/validate.proto"; |
||||
|
||||
service BlogService { |
||||
rpc CreateArticle (CreateArticleRequest) returns (CreateArticleReply) { |
||||
option (google.api.http) = { |
||||
post: "/v1/article/" |
||||
body: "*" |
||||
}; |
||||
} |
||||
rpc UpdateArticle (UpdateArticleRequest) returns (UpdateArticleReply) { |
||||
option (google.api.http) = { |
||||
put: "/v1/article/{id}" |
||||
body: "*" |
||||
}; |
||||
} |
||||
rpc DeleteArticle (DeleteArticleRequest) returns (DeleteArticleReply) { |
||||
option (google.api.http) = { |
||||
delete: "/v1/article/{id}" |
||||
}; |
||||
} |
||||
rpc GetArticle (GetArticleRequest) returns (GetArticleReply) { |
||||
option (google.api.http) = { |
||||
get: "/v1/article/{id}" |
||||
}; |
||||
} |
||||
rpc ListArticle (ListArticleRequest) returns (ListArticleReply) { |
||||
option (google.api.http) = { |
||||
get: "/v1/article/" |
||||
}; |
||||
} |
||||
} |
||||
|
||||
message Article { |
||||
int64 id = 1; |
||||
string title = 2; |
||||
string content = 3; |
||||
int64 like = 4; |
||||
} |
||||
|
||||
message CreateArticleRequest { |
||||
string title = 1 [(validate.rules).string = {min_len: 5, max_len: 50}]; // the title of string must be between 5 and 50 character |
||||
string content = 2; |
||||
} |
||||
|
||||
message CreateArticleReply { |
||||
Article Article = 1; |
||||
} |
||||
|
||||
message UpdateArticleRequest { |
||||
int64 id = 1 [(validate.rules).int64 = {gt: 0}]; |
||||
string title = 2 [(validate.rules).string = {min_len: 5, max_len: 50}]; // the title of string must be between 5 and 50 character; |
||||
string content = 3; |
||||
} |
||||
|
||||
message UpdateArticleReply { |
||||
Article Article = 1; |
||||
} |
||||
|
||||
message DeleteArticleRequest { |
||||
int64 id = 1; |
||||
} |
||||
message DeleteArticleReply { |
||||
} |
||||
|
||||
message GetArticleRequest { |
||||
int64 id = 1; |
||||
} |
||||
|
||||
message GetArticleReply { |
||||
Article Article = 1; |
||||
} |
||||
|
||||
message ListArticleRequest { |
||||
} |
||||
|
||||
message ListArticleReply { |
||||
repeated Article results = 1; |
||||
} |
@ -1,245 +0,0 @@ |
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
|
||||
package v1 |
||||
|
||||
import ( |
||||
context "context" |
||||
grpc "google.golang.org/grpc" |
||||
codes "google.golang.org/grpc/codes" |
||||
status "google.golang.org/grpc/status" |
||||
) |
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7 |
||||
|
||||
// BlogServiceClient is the client API for BlogService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type BlogServiceClient interface { |
||||
CreateArticle(ctx context.Context, in *CreateArticleRequest, opts ...grpc.CallOption) (*CreateArticleReply, error) |
||||
UpdateArticle(ctx context.Context, in *UpdateArticleRequest, opts ...grpc.CallOption) (*UpdateArticleReply, error) |
||||
DeleteArticle(ctx context.Context, in *DeleteArticleRequest, opts ...grpc.CallOption) (*DeleteArticleReply, error) |
||||
GetArticle(ctx context.Context, in *GetArticleRequest, opts ...grpc.CallOption) (*GetArticleReply, error) |
||||
ListArticle(ctx context.Context, in *ListArticleRequest, opts ...grpc.CallOption) (*ListArticleReply, error) |
||||
} |
||||
|
||||
type blogServiceClient struct { |
||||
cc grpc.ClientConnInterface |
||||
} |
||||
|
||||
func NewBlogServiceClient(cc grpc.ClientConnInterface) BlogServiceClient { |
||||
return &blogServiceClient{cc} |
||||
} |
||||
|
||||
func (c *blogServiceClient) CreateArticle(ctx context.Context, in *CreateArticleRequest, opts ...grpc.CallOption) (*CreateArticleReply, error) { |
||||
out := new(CreateArticleReply) |
||||
err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/CreateArticle", in, out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return out, nil |
||||
} |
||||
|
||||
func (c *blogServiceClient) UpdateArticle(ctx context.Context, in *UpdateArticleRequest, opts ...grpc.CallOption) (*UpdateArticleReply, error) { |
||||
out := new(UpdateArticleReply) |
||||
err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/UpdateArticle", in, out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return out, nil |
||||
} |
||||
|
||||
func (c *blogServiceClient) DeleteArticle(ctx context.Context, in *DeleteArticleRequest, opts ...grpc.CallOption) (*DeleteArticleReply, error) { |
||||
out := new(DeleteArticleReply) |
||||
err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/DeleteArticle", in, out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return out, nil |
||||
} |
||||
|
||||
func (c *blogServiceClient) GetArticle(ctx context.Context, in *GetArticleRequest, opts ...grpc.CallOption) (*GetArticleReply, error) { |
||||
out := new(GetArticleReply) |
||||
err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/GetArticle", in, out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return out, nil |
||||
} |
||||
|
||||
func (c *blogServiceClient) ListArticle(ctx context.Context, in *ListArticleRequest, opts ...grpc.CallOption) (*ListArticleReply, error) { |
||||
out := new(ListArticleReply) |
||||
err := c.cc.Invoke(ctx, "/blog.api.v1.BlogService/ListArticle", in, out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return out, nil |
||||
} |
||||
|
||||
// BlogServiceServer is the server API for BlogService service.
|
||||
// All implementations must embed UnimplementedBlogServiceServer
|
||||
// for forward compatibility
|
||||
type BlogServiceServer interface { |
||||
CreateArticle(context.Context, *CreateArticleRequest) (*CreateArticleReply, error) |
||||
UpdateArticle(context.Context, *UpdateArticleRequest) (*UpdateArticleReply, error) |
||||
DeleteArticle(context.Context, *DeleteArticleRequest) (*DeleteArticleReply, error) |
||||
GetArticle(context.Context, *GetArticleRequest) (*GetArticleReply, error) |
||||
ListArticle(context.Context, *ListArticleRequest) (*ListArticleReply, error) |
||||
mustEmbedUnimplementedBlogServiceServer() |
||||
} |
||||
|
||||
// UnimplementedBlogServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedBlogServiceServer struct { |
||||
} |
||||
|
||||
func (UnimplementedBlogServiceServer) CreateArticle(context.Context, *CreateArticleRequest) (*CreateArticleReply, error) { |
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateArticle not implemented") |
||||
} |
||||
func (UnimplementedBlogServiceServer) UpdateArticle(context.Context, *UpdateArticleRequest) (*UpdateArticleReply, error) { |
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateArticle not implemented") |
||||
} |
||||
func (UnimplementedBlogServiceServer) DeleteArticle(context.Context, *DeleteArticleRequest) (*DeleteArticleReply, error) { |
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteArticle not implemented") |
||||
} |
||||
func (UnimplementedBlogServiceServer) GetArticle(context.Context, *GetArticleRequest) (*GetArticleReply, error) { |
||||
return nil, status.Errorf(codes.Unimplemented, "method GetArticle not implemented") |
||||
} |
||||
func (UnimplementedBlogServiceServer) ListArticle(context.Context, *ListArticleRequest) (*ListArticleReply, error) { |
||||
return nil, status.Errorf(codes.Unimplemented, "method ListArticle not implemented") |
||||
} |
||||
func (UnimplementedBlogServiceServer) mustEmbedUnimplementedBlogServiceServer() {} |
||||
|
||||
// UnsafeBlogServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to BlogServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeBlogServiceServer interface { |
||||
mustEmbedUnimplementedBlogServiceServer() |
||||
} |
||||
|
||||
func RegisterBlogServiceServer(s grpc.ServiceRegistrar, srv BlogServiceServer) { |
||||
s.RegisterService(&BlogService_ServiceDesc, srv) |
||||
} |
||||
|
||||
func _BlogService_CreateArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { |
||||
in := new(CreateArticleRequest) |
||||
if err := dec(in); err != nil { |
||||
return nil, err |
||||
} |
||||
if interceptor == nil { |
||||
return srv.(BlogServiceServer).CreateArticle(ctx, in) |
||||
} |
||||
info := &grpc.UnaryServerInfo{ |
||||
Server: srv, |
||||
FullMethod: "/blog.api.v1.BlogService/CreateArticle", |
||||
} |
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.(BlogServiceServer).CreateArticle(ctx, req.(*CreateArticleRequest)) |
||||
} |
||||
return interceptor(ctx, in, info, handler) |
||||
} |
||||
|
||||
func _BlogService_UpdateArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { |
||||
in := new(UpdateArticleRequest) |
||||
if err := dec(in); err != nil { |
||||
return nil, err |
||||
} |
||||
if interceptor == nil { |
||||
return srv.(BlogServiceServer).UpdateArticle(ctx, in) |
||||
} |
||||
info := &grpc.UnaryServerInfo{ |
||||
Server: srv, |
||||
FullMethod: "/blog.api.v1.BlogService/UpdateArticle", |
||||
} |
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.(BlogServiceServer).UpdateArticle(ctx, req.(*UpdateArticleRequest)) |
||||
} |
||||
return interceptor(ctx, in, info, handler) |
||||
} |
||||
|
||||
func _BlogService_DeleteArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { |
||||
in := new(DeleteArticleRequest) |
||||
if err := dec(in); err != nil { |
||||
return nil, err |
||||
} |
||||
if interceptor == nil { |
||||
return srv.(BlogServiceServer).DeleteArticle(ctx, in) |
||||
} |
||||
info := &grpc.UnaryServerInfo{ |
||||
Server: srv, |
||||
FullMethod: "/blog.api.v1.BlogService/DeleteArticle", |
||||
} |
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.(BlogServiceServer).DeleteArticle(ctx, req.(*DeleteArticleRequest)) |
||||
} |
||||
return interceptor(ctx, in, info, handler) |
||||
} |
||||
|
||||
func _BlogService_GetArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { |
||||
in := new(GetArticleRequest) |
||||
if err := dec(in); err != nil { |
||||
return nil, err |
||||
} |
||||
if interceptor == nil { |
||||
return srv.(BlogServiceServer).GetArticle(ctx, in) |
||||
} |
||||
info := &grpc.UnaryServerInfo{ |
||||
Server: srv, |
||||
FullMethod: "/blog.api.v1.BlogService/GetArticle", |
||||
} |
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.(BlogServiceServer).GetArticle(ctx, req.(*GetArticleRequest)) |
||||
} |
||||
return interceptor(ctx, in, info, handler) |
||||
} |
||||
|
||||
func _BlogService_ListArticle_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { |
||||
in := new(ListArticleRequest) |
||||
if err := dec(in); err != nil { |
||||
return nil, err |
||||
} |
||||
if interceptor == nil { |
||||
return srv.(BlogServiceServer).ListArticle(ctx, in) |
||||
} |
||||
info := &grpc.UnaryServerInfo{ |
||||
Server: srv, |
||||
FullMethod: "/blog.api.v1.BlogService/ListArticle", |
||||
} |
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.(BlogServiceServer).ListArticle(ctx, req.(*ListArticleRequest)) |
||||
} |
||||
return interceptor(ctx, in, info, handler) |
||||
} |
||||
|
||||
// BlogService_ServiceDesc is the grpc.ServiceDesc for BlogService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var BlogService_ServiceDesc = grpc.ServiceDesc{ |
||||
ServiceName: "blog.api.v1.BlogService", |
||||
HandlerType: (*BlogServiceServer)(nil), |
||||
Methods: []grpc.MethodDesc{ |
||||
{ |
||||
MethodName: "CreateArticle", |
||||
Handler: _BlogService_CreateArticle_Handler, |
||||
}, |
||||
{ |
||||
MethodName: "UpdateArticle", |
||||
Handler: _BlogService_UpdateArticle_Handler, |
||||
}, |
||||
{ |
||||
MethodName: "DeleteArticle", |
||||
Handler: _BlogService_DeleteArticle_Handler, |
||||
}, |
||||
{ |
||||
MethodName: "GetArticle", |
||||
Handler: _BlogService_GetArticle_Handler, |
||||
}, |
||||
{ |
||||
MethodName: "ListArticle", |
||||
Handler: _BlogService_ListArticle_Handler, |
||||
}, |
||||
}, |
||||
Streams: []grpc.StreamDesc{}, |
||||
Metadata: "blog.proto", |
||||
} |
@ -1,220 +0,0 @@ |
||||
// Code generated by protoc-gen-go-http. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go-http v2.0.0
|
||||
|
||||
package v1 |
||||
|
||||
import ( |
||||
context "context" |
||||
http "github.com/go-kratos/kratos/v2/transport/http" |
||||
binding "github.com/go-kratos/kratos/v2/transport/http/binding" |
||||
) |
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the kratos package it is being compiled against.
|
||||
var _ = new(context.Context) |
||||
var _ = binding.EncodeURL |
||||
|
||||
const _ = http.SupportPackageIsVersion1 |
||||
|
||||
type BlogServiceHTTPServer interface { |
||||
CreateArticle(context.Context, *CreateArticleRequest) (*CreateArticleReply, error) |
||||
DeleteArticle(context.Context, *DeleteArticleRequest) (*DeleteArticleReply, error) |
||||
GetArticle(context.Context, *GetArticleRequest) (*GetArticleReply, error) |
||||
ListArticle(context.Context, *ListArticleRequest) (*ListArticleReply, error) |
||||
UpdateArticle(context.Context, *UpdateArticleRequest) (*UpdateArticleReply, error) |
||||
} |
||||
|
||||
func RegisterBlogServiceHTTPServer(s *http.Server, srv BlogServiceHTTPServer) { |
||||
r := s.Route("/") |
||||
r.POST("/v1/article/", _BlogService_CreateArticle0_HTTP_Handler(srv)) |
||||
r.PUT("/v1/article/{id}", _BlogService_UpdateArticle0_HTTP_Handler(srv)) |
||||
r.DELETE("/v1/article/{id}", _BlogService_DeleteArticle0_HTTP_Handler(srv)) |
||||
r.GET("/v1/article/{id}", _BlogService_GetArticle0_HTTP_Handler(srv)) |
||||
r.GET("/v1/article/", _BlogService_ListArticle0_HTTP_Handler(srv)) |
||||
} |
||||
|
||||
func _BlogService_CreateArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { |
||||
return func(ctx http.Context) error { |
||||
var in CreateArticleRequest |
||||
if err := ctx.Bind(&in); err != nil { |
||||
return err |
||||
} |
||||
http.SetOperation(ctx, "/blog.api.v1.BlogService/CreateArticle") |
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.CreateArticle(ctx, req.(*CreateArticleRequest)) |
||||
}) |
||||
out, err := h(ctx, &in) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
reply := out.(*CreateArticleReply) |
||||
return ctx.Result(200, reply) |
||||
} |
||||
} |
||||
|
||||
func _BlogService_UpdateArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { |
||||
return func(ctx http.Context) error { |
||||
var in UpdateArticleRequest |
||||
if err := ctx.Bind(&in); err != nil { |
||||
return err |
||||
} |
||||
if err := ctx.BindVars(&in); err != nil { |
||||
return err |
||||
} |
||||
http.SetOperation(ctx, "/blog.api.v1.BlogService/UpdateArticle") |
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.UpdateArticle(ctx, req.(*UpdateArticleRequest)) |
||||
}) |
||||
out, err := h(ctx, &in) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
reply := out.(*UpdateArticleReply) |
||||
return ctx.Result(200, reply) |
||||
} |
||||
} |
||||
|
||||
func _BlogService_DeleteArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { |
||||
return func(ctx http.Context) error { |
||||
var in DeleteArticleRequest |
||||
if err := ctx.BindQuery(&in); err != nil { |
||||
return err |
||||
} |
||||
if err := ctx.BindVars(&in); err != nil { |
||||
return err |
||||
} |
||||
http.SetOperation(ctx, "/blog.api.v1.BlogService/DeleteArticle") |
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.DeleteArticle(ctx, req.(*DeleteArticleRequest)) |
||||
}) |
||||
out, err := h(ctx, &in) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
reply := out.(*DeleteArticleReply) |
||||
return ctx.Result(200, reply) |
||||
} |
||||
} |
||||
|
||||
func _BlogService_GetArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { |
||||
return func(ctx http.Context) error { |
||||
var in GetArticleRequest |
||||
if err := ctx.BindQuery(&in); err != nil { |
||||
return err |
||||
} |
||||
if err := ctx.BindVars(&in); err != nil { |
||||
return err |
||||
} |
||||
http.SetOperation(ctx, "/blog.api.v1.BlogService/GetArticle") |
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.GetArticle(ctx, req.(*GetArticleRequest)) |
||||
}) |
||||
out, err := h(ctx, &in) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
reply := out.(*GetArticleReply) |
||||
return ctx.Result(200, reply) |
||||
} |
||||
} |
||||
|
||||
func _BlogService_ListArticle0_HTTP_Handler(srv BlogServiceHTTPServer) func(ctx http.Context) error { |
||||
return func(ctx http.Context) error { |
||||
var in ListArticleRequest |
||||
if err := ctx.BindQuery(&in); err != nil { |
||||
return err |
||||
} |
||||
http.SetOperation(ctx, "/blog.api.v1.BlogService/ListArticle") |
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { |
||||
return srv.ListArticle(ctx, req.(*ListArticleRequest)) |
||||
}) |
||||
out, err := h(ctx, &in) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
reply := out.(*ListArticleReply) |
||||
return ctx.Result(200, reply) |
||||
} |
||||
} |
||||
|
||||
type BlogServiceHTTPClient interface { |
||||
CreateArticle(ctx context.Context, req *CreateArticleRequest, opts ...http.CallOption) (rsp *CreateArticleReply, err error) |
||||
DeleteArticle(ctx context.Context, req *DeleteArticleRequest, opts ...http.CallOption) (rsp *DeleteArticleReply, err error) |
||||
GetArticle(ctx context.Context, req *GetArticleRequest, opts ...http.CallOption) (rsp *GetArticleReply, err error) |
||||
ListArticle(ctx context.Context, req *ListArticleRequest, opts ...http.CallOption) (rsp *ListArticleReply, err error) |
||||
UpdateArticle(ctx context.Context, req *UpdateArticleRequest, opts ...http.CallOption) (rsp *UpdateArticleReply, err error) |
||||
} |
||||
|
||||
type BlogServiceHTTPClientImpl struct { |
||||
cc *http.Client |
||||
} |
||||
|
||||
func NewBlogServiceHTTPClient(client *http.Client) BlogServiceHTTPClient { |
||||
return &BlogServiceHTTPClientImpl{client} |
||||
} |
||||
|
||||
func (c *BlogServiceHTTPClientImpl) CreateArticle(ctx context.Context, in *CreateArticleRequest, opts ...http.CallOption) (*CreateArticleReply, error) { |
||||
var out CreateArticleReply |
||||
pattern := "/v1/article/" |
||||
path := binding.EncodeURL(pattern, in, false) |
||||
opts = append(opts, http.Operation("/blog.api.v1.BlogService/CreateArticle")) |
||||
opts = append(opts, http.PathTemplate(pattern)) |
||||
err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return &out, err |
||||
} |
||||
|
||||
func (c *BlogServiceHTTPClientImpl) DeleteArticle(ctx context.Context, in *DeleteArticleRequest, opts ...http.CallOption) (*DeleteArticleReply, error) { |
||||
var out DeleteArticleReply |
||||
pattern := "/v1/article/{id}" |
||||
path := binding.EncodeURL(pattern, in, true) |
||||
opts = append(opts, http.Operation("/blog.api.v1.BlogService/DeleteArticle")) |
||||
opts = append(opts, http.PathTemplate(pattern)) |
||||
err := c.cc.Invoke(ctx, "DELETE", path, nil, &out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return &out, err |
||||
} |
||||
|
||||
func (c *BlogServiceHTTPClientImpl) GetArticle(ctx context.Context, in *GetArticleRequest, opts ...http.CallOption) (*GetArticleReply, error) { |
||||
var out GetArticleReply |
||||
pattern := "/v1/article/{id}" |
||||
path := binding.EncodeURL(pattern, in, true) |
||||
opts = append(opts, http.Operation("/blog.api.v1.BlogService/GetArticle")) |
||||
opts = append(opts, http.PathTemplate(pattern)) |
||||
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return &out, err |
||||
} |
||||
|
||||
func (c *BlogServiceHTTPClientImpl) ListArticle(ctx context.Context, in *ListArticleRequest, opts ...http.CallOption) (*ListArticleReply, error) { |
||||
var out ListArticleReply |
||||
pattern := "/v1/article/" |
||||
path := binding.EncodeURL(pattern, in, true) |
||||
opts = append(opts, http.Operation("/blog.api.v1.BlogService/ListArticle")) |
||||
opts = append(opts, http.PathTemplate(pattern)) |
||||
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return &out, err |
||||
} |
||||
|
||||
func (c *BlogServiceHTTPClientImpl) UpdateArticle(ctx context.Context, in *UpdateArticleRequest, opts ...http.CallOption) (*UpdateArticleReply, error) { |
||||
var out UpdateArticleReply |
||||
pattern := "/v1/article/{id}" |
||||
path := binding.EncodeURL(pattern, in, false) |
||||
opts = append(opts, http.Operation("/blog.api.v1.BlogService/UpdateArticle")) |
||||
opts = append(opts, http.PathTemplate(pattern)) |
||||
err := c.cc.Invoke(ctx, "PUT", path, in, &out, opts...) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return &out, err |
||||
} |
@ -1,103 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"flag" |
||||
"os" |
||||
|
||||
"github.com/go-kratos/kratos/examples/blog/internal/conf" |
||||
"github.com/go-kratos/kratos/v2" |
||||
"github.com/go-kratos/kratos/v2/config" |
||||
"github.com/go-kratos/kratos/v2/config/file" |
||||
"github.com/go-kratos/kratos/v2/log" |
||||
"github.com/go-kratos/kratos/v2/transport/grpc" |
||||
"github.com/go-kratos/kratos/v2/transport/http" |
||||
"go.opentelemetry.io/otel" |
||||
"go.opentelemetry.io/otel/attribute" |
||||
"go.opentelemetry.io/otel/exporters/jaeger" |
||||
"go.opentelemetry.io/otel/sdk/resource" |
||||
tracesdk "go.opentelemetry.io/otel/sdk/trace" |
||||
semconv "go.opentelemetry.io/otel/semconv/v1.4.0" |
||||
) |
||||
|
||||
// go build -ldflags "-X main.Version=x.y.z"
|
||||
var ( |
||||
// Name is the name of the compiled software.
|
||||
Name string |
||||
// Version is the version of the compiled software.
|
||||
Version string |
||||
// flagconf is the config flag.
|
||||
flagconf string |
||||
) |
||||
|
||||
func init() { |
||||
flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml") |
||||
} |
||||
|
||||
func newApp(logger log.Logger, hs *http.Server, gs *grpc.Server) *kratos.App { |
||||
return kratos.New( |
||||
kratos.Name(Name), |
||||
kratos.Version(Version), |
||||
kratos.Metadata(map[string]string{}), |
||||
kratos.Logger(logger), |
||||
kratos.Server( |
||||
hs, |
||||
gs, |
||||
), |
||||
) |
||||
} |
||||
|
||||
// Set global trace provider
|
||||
func setTracerProvider(url string) error { |
||||
// Create the Jaeger exporter
|
||||
exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
tp := tracesdk.NewTracerProvider( |
||||
// Set the sampling rate based on the parent span to 100%
|
||||
tracesdk.WithSampler(tracesdk.ParentBased(tracesdk.TraceIDRatioBased(1.0))), |
||||
// Always be sure to batch in production.
|
||||
tracesdk.WithBatcher(exp), |
||||
// Record information about this application in an Resource.
|
||||
tracesdk.WithResource(resource.NewSchemaless( |
||||
semconv.ServiceNameKey.String(Name), |
||||
attribute.String("env", "dev"), |
||||
)), |
||||
) |
||||
otel.SetTracerProvider(tp) |
||||
return nil |
||||
} |
||||
|
||||
func main() { |
||||
flag.Parse() |
||||
logger := log.NewStdLogger(os.Stdout) |
||||
|
||||
cfg := config.New( |
||||
config.WithSource( |
||||
file.NewSource(flagconf), |
||||
), |
||||
) |
||||
if err := cfg.Load(); err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
var bc conf.Bootstrap |
||||
if err := cfg.Scan(&bc); err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
if err := setTracerProvider(bc.Trace.Endpoint); err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
app, cleanup, err := initApp(bc.Server, bc.Data, logger) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
defer cleanup() |
||||
|
||||
// start and wait for stop signal
|
||||
if err := app.Run(); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
@ -1,22 +0,0 @@ |
||||
//go:build wireinject
|
||||
// +build wireinject
|
||||
|
||||
// The build tag makes sure the stub is not built in the final build.
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/go-kratos/kratos/examples/blog/internal/biz" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/conf" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/server" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/service" |
||||
"github.com/go-kratos/kratos/v2" |
||||
"github.com/go-kratos/kratos/v2/log" |
||||
"github.com/google/wire" |
||||
) |
||||
|
||||
// initApp init kratos application.
|
||||
func initApp(*conf.Server, *conf.Data, log.Logger) (*kratos.App, func(), error) { |
||||
panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp)) |
||||
} |
@ -1,36 +0,0 @@ |
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate go run github.com/google/wire/cmd/wire
|
||||
//go:build !wireinject
|
||||
// +build !wireinject
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/go-kratos/kratos/examples/blog/internal/biz" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/conf" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/server" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/service" |
||||
"github.com/go-kratos/kratos/v2" |
||||
"github.com/go-kratos/kratos/v2/log" |
||||
) |
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
// initApp init kratos application.
|
||||
func initApp(confServer *conf.Server, confData *conf.Data, logger log.Logger) (*kratos.App, func(), error) { |
||||
dataData, cleanup, err := data.NewData(confData, logger) |
||||
if err != nil { |
||||
return nil, nil, err |
||||
} |
||||
articleRepo := data.NewArticleRepo(dataData, logger) |
||||
articleUsecase := biz.NewArticleUsecase(articleRepo, logger) |
||||
blogService := service.NewBlogService(articleUsecase, logger) |
||||
httpServer := server.NewHTTPServer(confServer, logger, blogService) |
||||
grpcServer := server.NewGRPCServer(confServer, logger, blogService) |
||||
app := newApp(logger, httpServer, grpcServer) |
||||
return app, func() { |
||||
cleanup() |
||||
}, nil |
||||
} |
@ -1,18 +0,0 @@ |
||||
trace: |
||||
endpoint: http://127.0.0.1:14268/api/traces |
||||
server: |
||||
http: |
||||
addr: 0.0.0.0:8000 |
||||
timeout: 1s |
||||
grpc: |
||||
addr: 0.0.0.0:9000 |
||||
timeout: 1s |
||||
data: |
||||
database: |
||||
driver: mysql |
||||
source: root:password@tcp(127.0.0.1:3306)/testdb?parseTime=True |
||||
redis: |
||||
addr: 127.0.0.1:6379 |
||||
dial_timeout: 1s |
||||
read_timeout: 0.4s |
||||
write_timeout: 0.6s |
@ -1,3 +0,0 @@ |
||||
package generate |
||||
|
||||
//go:generate kratos proto client .
|
@ -1 +0,0 @@ |
||||
# Biz |
@ -1,74 +0,0 @@ |
||||
package biz |
||||
|
||||
import ( |
||||
"context" |
||||
"time" |
||||
|
||||
"github.com/go-kratos/kratos/v2/log" |
||||
) |
||||
|
||||
type Article struct { |
||||
ID int64 |
||||
Title string |
||||
Content string |
||||
CreatedAt time.Time |
||||
UpdatedAt time.Time |
||||
Like int64 |
||||
} |
||||
|
||||
type ArticleRepo interface { |
||||
// db
|
||||
ListArticle(ctx context.Context) ([]*Article, error) |
||||
GetArticle(ctx context.Context, id int64) (*Article, error) |
||||
CreateArticle(ctx context.Context, article *Article) error |
||||
UpdateArticle(ctx context.Context, id int64, article *Article) error |
||||
DeleteArticle(ctx context.Context, id int64) error |
||||
|
||||
// redis
|
||||
GetArticleLike(ctx context.Context, id int64) (rv int64, err error) |
||||
IncArticleLike(ctx context.Context, id int64) error |
||||
} |
||||
|
||||
type ArticleUsecase struct { |
||||
repo ArticleRepo |
||||
} |
||||
|
||||
func NewArticleUsecase(repo ArticleRepo, logger log.Logger) *ArticleUsecase { |
||||
return &ArticleUsecase{repo: repo} |
||||
} |
||||
|
||||
func (uc *ArticleUsecase) List(ctx context.Context) (ps []*Article, err error) { |
||||
ps, err = uc.repo.ListArticle(ctx) |
||||
if err != nil { |
||||
return |
||||
} |
||||
return |
||||
} |
||||
|
||||
func (uc *ArticleUsecase) Get(ctx context.Context, id int64) (p *Article, err error) { |
||||
p, err = uc.repo.GetArticle(ctx, id) |
||||
if err != nil { |
||||
return |
||||
} |
||||
err = uc.repo.IncArticleLike(ctx, id) |
||||
if err != nil { |
||||
return |
||||
} |
||||
p.Like, err = uc.repo.GetArticleLike(ctx, id) |
||||
if err != nil { |
||||
return |
||||
} |
||||
return |
||||
} |
||||
|
||||
func (uc *ArticleUsecase) Create(ctx context.Context, article *Article) error { |
||||
return uc.repo.CreateArticle(ctx, article) |
||||
} |
||||
|
||||
func (uc *ArticleUsecase) Update(ctx context.Context, id int64, article *Article) error { |
||||
return uc.repo.UpdateArticle(ctx, id, article) |
||||
} |
||||
|
||||
func (uc *ArticleUsecase) Delete(ctx context.Context, id int64) error { |
||||
return uc.repo.DeleteArticle(ctx, id) |
||||
} |
@ -1,6 +0,0 @@ |
||||
package biz |
||||
|
||||
import "github.com/google/wire" |
||||
|
||||
// ProviderSet is biz providers.
|
||||
var ProviderSet = wire.NewSet(NewArticleUsecase) |
@ -1,763 +0,0 @@ |
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.17.0
|
||||
// source: conf.proto
|
||||
|
||||
package conf |
||||
|
||||
import ( |
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect" |
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl" |
||||
durationpb "google.golang.org/protobuf/types/known/durationpb" |
||||
reflect "reflect" |
||||
sync "sync" |
||||
) |
||||
|
||||
const ( |
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) |
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) |
||||
) |
||||
|
||||
type Bootstrap struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Trace *Trace `protobuf:"bytes,1,opt,name=trace,proto3" json:"trace,omitempty"` |
||||
Server *Server `protobuf:"bytes,2,opt,name=server,proto3" json:"server,omitempty"` |
||||
Data *Data `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` |
||||
} |
||||
|
||||
func (x *Bootstrap) Reset() { |
||||
*x = Bootstrap{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_conf_proto_msgTypes[0] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Bootstrap) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Bootstrap) ProtoMessage() {} |
||||
|
||||
func (x *Bootstrap) ProtoReflect() protoreflect.Message { |
||||
mi := &file_conf_proto_msgTypes[0] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Bootstrap.ProtoReflect.Descriptor instead.
|
||||
func (*Bootstrap) Descriptor() ([]byte, []int) { |
||||
return file_conf_proto_rawDescGZIP(), []int{0} |
||||
} |
||||
|
||||
func (x *Bootstrap) GetTrace() *Trace { |
||||
if x != nil { |
||||
return x.Trace |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (x *Bootstrap) GetServer() *Server { |
||||
if x != nil { |
||||
return x.Server |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (x *Bootstrap) GetData() *Data { |
||||
if x != nil { |
||||
return x.Data |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type Server struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Http *Server_HTTP `protobuf:"bytes,1,opt,name=http,proto3" json:"http,omitempty"` |
||||
Grpc *Server_GRPC `protobuf:"bytes,2,opt,name=grpc,proto3" json:"grpc,omitempty"` |
||||
} |
||||
|
||||
func (x *Server) Reset() { |
||||
*x = Server{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_conf_proto_msgTypes[1] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Server) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Server) ProtoMessage() {} |
||||
|
||||
func (x *Server) ProtoReflect() protoreflect.Message { |
||||
mi := &file_conf_proto_msgTypes[1] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Server.ProtoReflect.Descriptor instead.
|
||||
func (*Server) Descriptor() ([]byte, []int) { |
||||
return file_conf_proto_rawDescGZIP(), []int{1} |
||||
} |
||||
|
||||
func (x *Server) GetHttp() *Server_HTTP { |
||||
if x != nil { |
||||
return x.Http |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (x *Server) GetGrpc() *Server_GRPC { |
||||
if x != nil { |
||||
return x.Grpc |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type Data struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Database *Data_Database `protobuf:"bytes,1,opt,name=database,proto3" json:"database,omitempty"` |
||||
Redis *Data_Redis `protobuf:"bytes,2,opt,name=redis,proto3" json:"redis,omitempty"` |
||||
} |
||||
|
||||
func (x *Data) Reset() { |
||||
*x = Data{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_conf_proto_msgTypes[2] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Data) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Data) ProtoMessage() {} |
||||
|
||||
func (x *Data) ProtoReflect() protoreflect.Message { |
||||
mi := &file_conf_proto_msgTypes[2] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Data.ProtoReflect.Descriptor instead.
|
||||
func (*Data) Descriptor() ([]byte, []int) { |
||||
return file_conf_proto_rawDescGZIP(), []int{2} |
||||
} |
||||
|
||||
func (x *Data) GetDatabase() *Data_Database { |
||||
if x != nil { |
||||
return x.Database |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (x *Data) GetRedis() *Data_Redis { |
||||
if x != nil { |
||||
return x.Redis |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type Trace struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Endpoint string `protobuf:"bytes,1,opt,name=endpoint,proto3" json:"endpoint,omitempty"` |
||||
} |
||||
|
||||
func (x *Trace) Reset() { |
||||
*x = Trace{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_conf_proto_msgTypes[3] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Trace) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Trace) ProtoMessage() {} |
||||
|
||||
func (x *Trace) ProtoReflect() protoreflect.Message { |
||||
mi := &file_conf_proto_msgTypes[3] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Trace.ProtoReflect.Descriptor instead.
|
||||
func (*Trace) Descriptor() ([]byte, []int) { |
||||
return file_conf_proto_rawDescGZIP(), []int{3} |
||||
} |
||||
|
||||
func (x *Trace) GetEndpoint() string { |
||||
if x != nil { |
||||
return x.Endpoint |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
type Server_HTTP struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` |
||||
Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` |
||||
Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` |
||||
} |
||||
|
||||
func (x *Server_HTTP) Reset() { |
||||
*x = Server_HTTP{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_conf_proto_msgTypes[4] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Server_HTTP) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Server_HTTP) ProtoMessage() {} |
||||
|
||||
func (x *Server_HTTP) ProtoReflect() protoreflect.Message { |
||||
mi := &file_conf_proto_msgTypes[4] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Server_HTTP.ProtoReflect.Descriptor instead.
|
||||
func (*Server_HTTP) Descriptor() ([]byte, []int) { |
||||
return file_conf_proto_rawDescGZIP(), []int{1, 0} |
||||
} |
||||
|
||||
func (x *Server_HTTP) GetNetwork() string { |
||||
if x != nil { |
||||
return x.Network |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Server_HTTP) GetAddr() string { |
||||
if x != nil { |
||||
return x.Addr |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Server_HTTP) GetTimeout() *durationpb.Duration { |
||||
if x != nil { |
||||
return x.Timeout |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type Server_GRPC struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` |
||||
Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` |
||||
Timeout *durationpb.Duration `protobuf:"bytes,3,opt,name=timeout,proto3" json:"timeout,omitempty"` |
||||
} |
||||
|
||||
func (x *Server_GRPC) Reset() { |
||||
*x = Server_GRPC{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_conf_proto_msgTypes[5] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Server_GRPC) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Server_GRPC) ProtoMessage() {} |
||||
|
||||
func (x *Server_GRPC) ProtoReflect() protoreflect.Message { |
||||
mi := &file_conf_proto_msgTypes[5] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Server_GRPC.ProtoReflect.Descriptor instead.
|
||||
func (*Server_GRPC) Descriptor() ([]byte, []int) { |
||||
return file_conf_proto_rawDescGZIP(), []int{1, 1} |
||||
} |
||||
|
||||
func (x *Server_GRPC) GetNetwork() string { |
||||
if x != nil { |
||||
return x.Network |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Server_GRPC) GetAddr() string { |
||||
if x != nil { |
||||
return x.Addr |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Server_GRPC) GetTimeout() *durationpb.Duration { |
||||
if x != nil { |
||||
return x.Timeout |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
type Data_Database struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Driver string `protobuf:"bytes,1,opt,name=driver,proto3" json:"driver,omitempty"` |
||||
Source string `protobuf:"bytes,2,opt,name=source,proto3" json:"source,omitempty"` |
||||
} |
||||
|
||||
func (x *Data_Database) Reset() { |
||||
*x = Data_Database{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_conf_proto_msgTypes[6] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Data_Database) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Data_Database) ProtoMessage() {} |
||||
|
||||
func (x *Data_Database) ProtoReflect() protoreflect.Message { |
||||
mi := &file_conf_proto_msgTypes[6] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Data_Database.ProtoReflect.Descriptor instead.
|
||||
func (*Data_Database) Descriptor() ([]byte, []int) { |
||||
return file_conf_proto_rawDescGZIP(), []int{2, 0} |
||||
} |
||||
|
||||
func (x *Data_Database) GetDriver() string { |
||||
if x != nil { |
||||
return x.Driver |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Data_Database) GetSource() string { |
||||
if x != nil { |
||||
return x.Source |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
type Data_Redis struct { |
||||
state protoimpl.MessageState |
||||
sizeCache protoimpl.SizeCache |
||||
unknownFields protoimpl.UnknownFields |
||||
|
||||
Network string `protobuf:"bytes,1,opt,name=network,proto3" json:"network,omitempty"` |
||||
Addr string `protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"` |
||||
Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"` |
||||
Db int32 `protobuf:"varint,4,opt,name=db,proto3" json:"db,omitempty"` |
||||
DialTimeout *durationpb.Duration `protobuf:"bytes,5,opt,name=dial_timeout,json=dialTimeout,proto3" json:"dial_timeout,omitempty"` |
||||
ReadTimeout *durationpb.Duration `protobuf:"bytes,6,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"` |
||||
WriteTimeout *durationpb.Duration `protobuf:"bytes,7,opt,name=write_timeout,json=writeTimeout,proto3" json:"write_timeout,omitempty"` |
||||
} |
||||
|
||||
func (x *Data_Redis) Reset() { |
||||
*x = Data_Redis{} |
||||
if protoimpl.UnsafeEnabled { |
||||
mi := &file_conf_proto_msgTypes[7] |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
} |
||||
|
||||
func (x *Data_Redis) String() string { |
||||
return protoimpl.X.MessageStringOf(x) |
||||
} |
||||
|
||||
func (*Data_Redis) ProtoMessage() {} |
||||
|
||||
func (x *Data_Redis) ProtoReflect() protoreflect.Message { |
||||
mi := &file_conf_proto_msgTypes[7] |
||||
if protoimpl.UnsafeEnabled && x != nil { |
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) |
||||
if ms.LoadMessageInfo() == nil { |
||||
ms.StoreMessageInfo(mi) |
||||
} |
||||
return ms |
||||
} |
||||
return mi.MessageOf(x) |
||||
} |
||||
|
||||
// Deprecated: Use Data_Redis.ProtoReflect.Descriptor instead.
|
||||
func (*Data_Redis) Descriptor() ([]byte, []int) { |
||||
return file_conf_proto_rawDescGZIP(), []int{2, 1} |
||||
} |
||||
|
||||
func (x *Data_Redis) GetNetwork() string { |
||||
if x != nil { |
||||
return x.Network |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Data_Redis) GetAddr() string { |
||||
if x != nil { |
||||
return x.Addr |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Data_Redis) GetPassword() string { |
||||
if x != nil { |
||||
return x.Password |
||||
} |
||||
return "" |
||||
} |
||||
|
||||
func (x *Data_Redis) GetDb() int32 { |
||||
if x != nil { |
||||
return x.Db |
||||
} |
||||
return 0 |
||||
} |
||||
|
||||
func (x *Data_Redis) GetDialTimeout() *durationpb.Duration { |
||||
if x != nil { |
||||
return x.DialTimeout |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (x *Data_Redis) GetReadTimeout() *durationpb.Duration { |
||||
if x != nil { |
||||
return x.ReadTimeout |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (x *Data_Redis) GetWriteTimeout() *durationpb.Duration { |
||||
if x != nil { |
||||
return x.WriteTimeout |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
var File_conf_proto protoreflect.FileDescriptor |
||||
|
||||
var file_conf_proto_rawDesc = []byte{ |
||||
0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x14, 0x6b, 0x72, |
||||
0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, |
||||
0x6e, 0x66, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, |
||||
0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, |
||||
0x74, 0x6f, 0x22, 0xa4, 0x01, 0x0a, 0x09, 0x42, 0x6f, 0x6f, 0x74, 0x73, 0x74, 0x72, 0x61, 0x70, |
||||
0x12, 0x31, 0x0a, 0x05, 0x74, 0x72, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, |
||||
0x1b, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, |
||||
0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x65, 0x52, 0x05, 0x74, 0x72, |
||||
0x61, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x02, 0x20, |
||||
0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, |
||||
0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, |
||||
0x72, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x2e, 0x0a, 0x04, 0x64, 0x61, 0x74, |
||||
0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, |
||||
0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, |
||||
0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xcc, 0x02, 0x0a, 0x06, 0x53, 0x65, |
||||
0x72, 0x76, 0x65, 0x72, 0x12, 0x35, 0x0a, 0x04, 0x68, 0x74, 0x74, 0x70, 0x18, 0x01, 0x20, 0x01, |
||||
0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, |
||||
0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, |
||||
0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x04, 0x68, 0x74, 0x74, 0x70, 0x12, 0x35, 0x0a, 0x04, 0x67, |
||||
0x72, 0x70, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6b, 0x72, 0x61, 0x74, |
||||
0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, |
||||
0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x47, 0x52, 0x50, 0x43, 0x52, 0x04, 0x67, 0x72, |
||||
0x70, 0x63, 0x1a, 0x69, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, |
||||
0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, |
||||
0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, |
||||
0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, |
||||
0x6f, 0x75, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, |
||||
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, |
||||
0x74, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x1a, 0x69, 0x0a, |
||||
0x04, 0x47, 0x52, 0x50, 0x43, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, |
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, |
||||
0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, |
||||
0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x03, |
||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, |
||||
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, |
||||
0x07, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0xdb, 0x03, 0x0a, 0x04, 0x44, 0x61, 0x74, |
||||
0x61, 0x12, 0x3f, 0x0a, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, |
||||
0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, |
||||
0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, |
||||
0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, |
||||
0x73, 0x65, 0x12, 0x36, 0x0a, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, |
||||
0x0b, 0x32, 0x20, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, |
||||
0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x52, 0x65, |
||||
0x64, 0x69, 0x73, 0x52, 0x05, 0x72, 0x65, 0x64, 0x69, 0x73, 0x1a, 0x3a, 0x0a, 0x08, 0x44, 0x61, |
||||
0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, |
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x12, 0x16, |
||||
0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, |
||||
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x9d, 0x02, 0x0a, 0x05, 0x52, 0x65, 0x64, 0x69, 0x73, |
||||
0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, |
||||
0x09, 0x52, 0x07, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, |
||||
0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x1a, |
||||
0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, |
||||
0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x64, 0x62, |
||||
0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x64, 0x62, 0x12, 0x3c, 0x0a, 0x0c, 0x64, 0x69, |
||||
0x61, 0x6c, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, |
||||
0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, |
||||
0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x64, 0x69, 0x61, |
||||
0x6c, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3c, 0x0a, 0x0c, 0x72, 0x65, 0x61, 0x64, |
||||
0x5f, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, |
||||
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, |
||||
0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72, 0x65, 0x61, 0x64, 0x54, |
||||
0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x3e, 0x0a, 0x0d, 0x77, 0x72, 0x69, 0x74, 0x65, 0x5f, |
||||
0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, |
||||
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, |
||||
0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x77, 0x72, 0x69, 0x74, 0x65, 0x54, |
||||
0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x22, 0x23, 0x0a, 0x05, 0x54, 0x72, 0x61, 0x63, 0x65, 0x12, |
||||
0x1a, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, |
||||
0x09, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x42, 0x3e, 0x5a, 0x3c, 0x67, |
||||
0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, |
||||
0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, |
||||
0x6c, 0x65, 0x73, 0x2f, 0x62, 0x6c, 0x6f, 0x67, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, |
||||
0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, |
||||
0x74, 0x6f, 0x33, |
||||
} |
||||
|
||||
var ( |
||||
file_conf_proto_rawDescOnce sync.Once |
||||
file_conf_proto_rawDescData = file_conf_proto_rawDesc |
||||
) |
||||
|
||||
func file_conf_proto_rawDescGZIP() []byte { |
||||
file_conf_proto_rawDescOnce.Do(func() { |
||||
file_conf_proto_rawDescData = protoimpl.X.CompressGZIP(file_conf_proto_rawDescData) |
||||
}) |
||||
return file_conf_proto_rawDescData |
||||
} |
||||
|
||||
var file_conf_proto_msgTypes = make([]protoimpl.MessageInfo, 8) |
||||
var file_conf_proto_goTypes = []interface{}{ |
||||
(*Bootstrap)(nil), // 0: kratos.internal.conf.Bootstrap
|
||||
(*Server)(nil), // 1: kratos.internal.conf.Server
|
||||
(*Data)(nil), // 2: kratos.internal.conf.Data
|
||||
(*Trace)(nil), // 3: kratos.internal.conf.Trace
|
||||
(*Server_HTTP)(nil), // 4: kratos.internal.conf.Server.HTTP
|
||||
(*Server_GRPC)(nil), // 5: kratos.internal.conf.Server.GRPC
|
||||
(*Data_Database)(nil), // 6: kratos.internal.conf.Data.Database
|
||||
(*Data_Redis)(nil), // 7: kratos.internal.conf.Data.Redis
|
||||
(*durationpb.Duration)(nil), // 8: google.protobuf.Duration
|
||||
} |
||||
var file_conf_proto_depIdxs = []int32{ |
||||
3, // 0: kratos.internal.conf.Bootstrap.trace:type_name -> kratos.internal.conf.Trace
|
||||
1, // 1: kratos.internal.conf.Bootstrap.server:type_name -> kratos.internal.conf.Server
|
||||
2, // 2: kratos.internal.conf.Bootstrap.data:type_name -> kratos.internal.conf.Data
|
||||
4, // 3: kratos.internal.conf.Server.http:type_name -> kratos.internal.conf.Server.HTTP
|
||||
5, // 4: kratos.internal.conf.Server.grpc:type_name -> kratos.internal.conf.Server.GRPC
|
||||
6, // 5: kratos.internal.conf.Data.database:type_name -> kratos.internal.conf.Data.Database
|
||||
7, // 6: kratos.internal.conf.Data.redis:type_name -> kratos.internal.conf.Data.Redis
|
||||
8, // 7: kratos.internal.conf.Server.HTTP.timeout:type_name -> google.protobuf.Duration
|
||||
8, // 8: kratos.internal.conf.Server.GRPC.timeout:type_name -> google.protobuf.Duration
|
||||
8, // 9: kratos.internal.conf.Data.Redis.dial_timeout:type_name -> google.protobuf.Duration
|
||||
8, // 10: kratos.internal.conf.Data.Redis.read_timeout:type_name -> google.protobuf.Duration
|
||||
8, // 11: kratos.internal.conf.Data.Redis.write_timeout:type_name -> google.protobuf.Duration
|
||||
12, // [12:12] is the sub-list for method output_type
|
||||
12, // [12:12] is the sub-list for method input_type
|
||||
12, // [12:12] is the sub-list for extension type_name
|
||||
12, // [12:12] is the sub-list for extension extendee
|
||||
0, // [0:12] is the sub-list for field type_name
|
||||
} |
||||
|
||||
func init() { file_conf_proto_init() } |
||||
func file_conf_proto_init() { |
||||
if File_conf_proto != nil { |
||||
return |
||||
} |
||||
if !protoimpl.UnsafeEnabled { |
||||
file_conf_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Bootstrap); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_conf_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Server); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_conf_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Data); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_conf_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Trace); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_conf_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Server_HTTP); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_conf_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Server_GRPC); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_conf_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Data_Database); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
file_conf_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { |
||||
switch v := v.(*Data_Redis); i { |
||||
case 0: |
||||
return &v.state |
||||
case 1: |
||||
return &v.sizeCache |
||||
case 2: |
||||
return &v.unknownFields |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
} |
||||
type x struct{} |
||||
out := protoimpl.TypeBuilder{ |
||||
File: protoimpl.DescBuilder{ |
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), |
||||
RawDescriptor: file_conf_proto_rawDesc, |
||||
NumEnums: 0, |
||||
NumMessages: 8, |
||||
NumExtensions: 0, |
||||
NumServices: 0, |
||||
}, |
||||
GoTypes: file_conf_proto_goTypes, |
||||
DependencyIndexes: file_conf_proto_depIdxs, |
||||
MessageInfos: file_conf_proto_msgTypes, |
||||
}.Build() |
||||
File_conf_proto = out.File |
||||
file_conf_proto_rawDesc = nil |
||||
file_conf_proto_goTypes = nil |
||||
file_conf_proto_depIdxs = nil |
||||
} |
@ -1,49 +0,0 @@ |
||||
syntax = "proto3"; |
||||
package kratos.internal.conf; |
||||
|
||||
option go_package = "github.com/go-kratos/kratos/examples/blog/internal/conf;conf"; |
||||
|
||||
import "google/protobuf/duration.proto"; |
||||
|
||||
message Bootstrap { |
||||
Trace trace = 1; |
||||
Server server = 2; |
||||
Data data = 3; |
||||
} |
||||
|
||||
message Server { |
||||
message HTTP { |
||||
string network = 1; |
||||
string addr = 2; |
||||
google.protobuf.Duration timeout = 3; |
||||
} |
||||
message GRPC { |
||||
string network = 1; |
||||
string addr = 2; |
||||
google.protobuf.Duration timeout = 3; |
||||
} |
||||
HTTP http = 1; |
||||
GRPC grpc = 2; |
||||
} |
||||
|
||||
message Data { |
||||
message Database { |
||||
string driver = 1; |
||||
string source = 2; |
||||
} |
||||
message Redis { |
||||
string network = 1; |
||||
string addr = 2; |
||||
string password = 3; |
||||
int32 db = 4; |
||||
google.protobuf.Duration dial_timeout = 5; |
||||
google.protobuf.Duration read_timeout = 6; |
||||
google.protobuf.Duration write_timeout = 7; |
||||
} |
||||
Database database = 1; |
||||
Redis redis = 2; |
||||
} |
||||
|
||||
message Trace { |
||||
string endpoint = 1; |
||||
} |
@ -1,5 +0,0 @@ |
||||
# Data |
||||
|
||||
``` |
||||
go generate ./ent |
||||
``` |
@ -1,80 +0,0 @@ |
||||
package data |
||||
|
||||
import ( |
||||
"context" |
||||
"time" |
||||
|
||||
"github.com/go-kratos/kratos/examples/blog/internal/biz" |
||||
"github.com/go-kratos/kratos/v2/log" |
||||
) |
||||
|
||||
type articleRepo struct { |
||||
data *Data |
||||
log *log.Helper |
||||
} |
||||
|
||||
// NewArticleRepo .
|
||||
func NewArticleRepo(data *Data, logger log.Logger) biz.ArticleRepo { |
||||
return &articleRepo{ |
||||
data: data, |
||||
log: log.NewHelper(logger), |
||||
} |
||||
} |
||||
|
||||
func (ar *articleRepo) ListArticle(ctx context.Context) ([]*biz.Article, error) { |
||||
ps, err := ar.data.db.Article.Query().All(ctx) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
rv := make([]*biz.Article, 0, len(ps)) |
||||
for _, p := range ps { |
||||
rv = append(rv, &biz.Article{ |
||||
ID: p.ID, |
||||
Title: p.Title, |
||||
Content: p.Content, |
||||
CreatedAt: p.CreatedAt, |
||||
UpdatedAt: p.UpdatedAt, |
||||
}) |
||||
} |
||||
return rv, nil |
||||
} |
||||
|
||||
func (ar *articleRepo) GetArticle(ctx context.Context, id int64) (*biz.Article, error) { |
||||
p, err := ar.data.db.Article.Get(ctx, id) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return &biz.Article{ |
||||
ID: p.ID, |
||||
Title: p.Title, |
||||
Content: p.Content, |
||||
CreatedAt: p.CreatedAt, |
||||
UpdatedAt: p.UpdatedAt, |
||||
}, nil |
||||
} |
||||
|
||||
func (ar *articleRepo) CreateArticle(ctx context.Context, article *biz.Article) error { |
||||
_, err := ar.data.db.Article. |
||||
Create(). |
||||
SetTitle(article.Title). |
||||
SetContent(article.Content). |
||||
Save(ctx) |
||||
return err |
||||
} |
||||
|
||||
func (ar *articleRepo) UpdateArticle(ctx context.Context, id int64, article *biz.Article) error { |
||||
p, err := ar.data.db.Article.Get(ctx, id) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
_, err = p.Update(). |
||||
SetTitle(article.Title). |
||||
SetContent(article.Content). |
||||
SetUpdatedAt(time.Now()). |
||||
Save(ctx) |
||||
return err |
||||
} |
||||
|
||||
func (ar *articleRepo) DeleteArticle(ctx context.Context, id int64) error { |
||||
return ar.data.db.Article.DeleteOneID(id).Exec(ctx) |
||||
} |
@ -1,86 +0,0 @@ |
||||
package data |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
|
||||
"github.com/go-kratos/kratos/examples/blog/internal/conf" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent" |
||||
|
||||
"entgo.io/ent/dialect" |
||||
"entgo.io/ent/dialect/sql" |
||||
"github.com/go-kratos/kratos/v2/log" |
||||
"github.com/go-redis/redis/extra/redisotel" |
||||
"github.com/go-redis/redis/v8" |
||||
"github.com/google/wire" |
||||
"go.opentelemetry.io/otel" |
||||
"go.opentelemetry.io/otel/attribute" |
||||
"go.opentelemetry.io/otel/trace" |
||||
|
||||
// init mysql driver
|
||||
_ "github.com/go-sql-driver/mysql" |
||||
) |
||||
|
||||
// ProviderSet is data providers.
|
||||
var ProviderSet = wire.NewSet(NewData, NewArticleRepo) |
||||
|
||||
// Data .
|
||||
type Data struct { |
||||
db *ent.Client |
||||
rdb *redis.Client |
||||
} |
||||
|
||||
// NewData .
|
||||
func NewData(conf *conf.Data, logger log.Logger) (*Data, func(), error) { |
||||
log := log.NewHelper(logger) |
||||
drv, err := sql.Open( |
||||
conf.Database.Driver, |
||||
conf.Database.Source, |
||||
) |
||||
sqlDrv := dialect.DebugWithContext(drv, func(ctx context.Context, i ...interface{}) { |
||||
log.WithContext(ctx).Info(i...) |
||||
tracer := otel.Tracer("ent.") |
||||
kind := trace.SpanKindServer |
||||
_, span := tracer.Start(ctx, |
||||
"Query", |
||||
trace.WithAttributes( |
||||
attribute.String("sql", fmt.Sprint(i...)), |
||||
), |
||||
trace.WithSpanKind(kind), |
||||
) |
||||
span.End() |
||||
}) |
||||
client := ent.NewClient(ent.Driver(sqlDrv)) |
||||
if err != nil { |
||||
log.Errorf("failed opening connection to sqlite: %v", err) |
||||
return nil, nil, err |
||||
} |
||||
// Run the auto migration tool.
|
||||
if err := client.Schema.Create(context.Background()); err != nil { |
||||
log.Errorf("failed creating schema resources: %v", err) |
||||
return nil, nil, err |
||||
} |
||||
|
||||
rdb := redis.NewClient(&redis.Options{ |
||||
Addr: conf.Redis.Addr, |
||||
Password: conf.Redis.Password, |
||||
DB: int(conf.Redis.Db), |
||||
DialTimeout: conf.Redis.DialTimeout.AsDuration(), |
||||
WriteTimeout: conf.Redis.WriteTimeout.AsDuration(), |
||||
ReadTimeout: conf.Redis.ReadTimeout.AsDuration(), |
||||
}) |
||||
rdb.AddHook(redisotel.TracingHook{}) |
||||
d := &Data{ |
||||
db: client, |
||||
rdb: rdb, |
||||
} |
||||
return d, func() { |
||||
log.Info("message", "closing the data resources") |
||||
if err := d.db.Close(); err != nil { |
||||
log.Error(err) |
||||
} |
||||
if err := d.rdb.Close(); err != nil { |
||||
log.Error(err) |
||||
} |
||||
}, nil |
||||
} |
@ -1,174 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strings" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
) |
||||
|
||||
// Article is the model entity for the Article schema.
|
||||
type Article struct { |
||||
config `json:"-"` |
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"` |
||||
// Title holds the value of the "title" field.
|
||||
Title string `json:"title,omitempty"` |
||||
// Content holds the value of the "content" field.
|
||||
Content string `json:"content,omitempty"` |
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"` |
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"` |
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the ArticleQuery when eager-loading is set.
|
||||
Edges ArticleEdges `json:"edges"` |
||||
} |
||||
|
||||
// ArticleEdges holds the relations/edges for other nodes in the graph.
|
||||
type ArticleEdges struct { |
||||
// Comments holds the value of the comments edge.
|
||||
Comments []*Comment `json:"comments,omitempty"` |
||||
// Tags holds the value of the tags edge.
|
||||
Tags []*Tag `json:"tags,omitempty"` |
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool |
||||
} |
||||
|
||||
// CommentsOrErr returns the Comments value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e ArticleEdges) CommentsOrErr() ([]*Comment, error) { |
||||
if e.loadedTypes[0] { |
||||
return e.Comments, nil |
||||
} |
||||
return nil, &NotLoadedError{edge: "comments"} |
||||
} |
||||
|
||||
// TagsOrErr returns the Tags value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e ArticleEdges) TagsOrErr() ([]*Tag, error) { |
||||
if e.loadedTypes[1] { |
||||
return e.Tags, nil |
||||
} |
||||
return nil, &NotLoadedError{edge: "tags"} |
||||
} |
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Article) scanValues(columns []string) ([]interface{}, error) { |
||||
values := make([]interface{}, len(columns)) |
||||
for i := range columns { |
||||
switch columns[i] { |
||||
case article.FieldID: |
||||
values[i] = &sql.NullInt64{} |
||||
case article.FieldTitle, article.FieldContent: |
||||
values[i] = &sql.NullString{} |
||||
case article.FieldCreatedAt, article.FieldUpdatedAt: |
||||
values[i] = &sql.NullTime{} |
||||
default: |
||||
return nil, fmt.Errorf("unexpected column %q for type Article", columns[i]) |
||||
} |
||||
} |
||||
return values, nil |
||||
} |
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Article fields.
|
||||
func (a *Article) assignValues(columns []string, values []interface{}) error { |
||||
if m, n := len(values), len(columns); m < n { |
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) |
||||
} |
||||
for i := range columns { |
||||
switch columns[i] { |
||||
case article.FieldID: |
||||
value, ok := values[i].(*sql.NullInt64) |
||||
if !ok { |
||||
return fmt.Errorf("unexpected type %T for field id", value) |
||||
} |
||||
a.ID = int64(value.Int64) |
||||
case article.FieldTitle: |
||||
if value, ok := values[i].(*sql.NullString); !ok { |
||||
return fmt.Errorf("unexpected type %T for field title", values[i]) |
||||
} else if value.Valid { |
||||
a.Title = value.String |
||||
} |
||||
case article.FieldContent: |
||||
if value, ok := values[i].(*sql.NullString); !ok { |
||||
return fmt.Errorf("unexpected type %T for field content", values[i]) |
||||
} else if value.Valid { |
||||
a.Content = value.String |
||||
} |
||||
case article.FieldCreatedAt: |
||||
if value, ok := values[i].(*sql.NullTime); !ok { |
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i]) |
||||
} else if value.Valid { |
||||
a.CreatedAt = value.Time |
||||
} |
||||
case article.FieldUpdatedAt: |
||||
if value, ok := values[i].(*sql.NullTime); !ok { |
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i]) |
||||
} else if value.Valid { |
||||
a.UpdatedAt = value.Time |
||||
} |
||||
} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// QueryComments queries the "comments" edge of the Article entity.
|
||||
func (a *Article) QueryComments() *CommentQuery { |
||||
return (&ArticleClient{config: a.config}).QueryComments(a) |
||||
} |
||||
|
||||
// QueryTags queries the "tags" edge of the Article entity.
|
||||
func (a *Article) QueryTags() *TagQuery { |
||||
return (&ArticleClient{config: a.config}).QueryTags(a) |
||||
} |
||||
|
||||
// Update returns a builder for updating this Article.
|
||||
// Note that you need to call Article.Unwrap() before calling this method if this Article
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (a *Article) Update() *ArticleUpdateOne { |
||||
return (&ArticleClient{config: a.config}).UpdateOne(a) |
||||
} |
||||
|
||||
// Unwrap unwraps the Article entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (a *Article) Unwrap() *Article { |
||||
tx, ok := a.config.driver.(*txDriver) |
||||
if !ok { |
||||
panic("ent: Article is not a transactional entity") |
||||
} |
||||
a.config.driver = tx.drv |
||||
return a |
||||
} |
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (a *Article) String() string { |
||||
var builder strings.Builder |
||||
builder.WriteString("Article(") |
||||
builder.WriteString(fmt.Sprintf("id=%v", a.ID)) |
||||
builder.WriteString(", title=") |
||||
builder.WriteString(a.Title) |
||||
builder.WriteString(", content=") |
||||
builder.WriteString(a.Content) |
||||
builder.WriteString(", created_at=") |
||||
builder.WriteString(a.CreatedAt.Format(time.ANSIC)) |
||||
builder.WriteString(", updated_at=") |
||||
builder.WriteString(a.UpdatedAt.Format(time.ANSIC)) |
||||
builder.WriteByte(')') |
||||
return builder.String() |
||||
} |
||||
|
||||
// Articles is a parsable slice of Article.
|
||||
type Articles []*Article |
||||
|
||||
func (a Articles) config(cfg config) { |
||||
for _i := range a { |
||||
a[_i].config = cfg |
||||
} |
||||
} |
@ -1,74 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package article |
||||
|
||||
import ( |
||||
"time" |
||||
) |
||||
|
||||
const ( |
||||
// Label holds the string label denoting the article type in the database.
|
||||
Label = "article" |
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id" |
||||
// FieldTitle holds the string denoting the title field in the database.
|
||||
FieldTitle = "title" |
||||
// FieldContent holds the string denoting the content field in the database.
|
||||
FieldContent = "content" |
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at" |
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at" |
||||
|
||||
// EdgeComments holds the string denoting the comments edge name in mutations.
|
||||
EdgeComments = "comments" |
||||
// EdgeTags holds the string denoting the tags edge name in mutations.
|
||||
EdgeTags = "tags" |
||||
|
||||
// Table holds the table name of the article in the database.
|
||||
Table = "articles" |
||||
// CommentsTable is the table the holds the comments relation/edge.
|
||||
CommentsTable = "comments" |
||||
// CommentsInverseTable is the table name for the Comment entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "comment" package.
|
||||
CommentsInverseTable = "comments" |
||||
// CommentsColumn is the table column denoting the comments relation/edge.
|
||||
CommentsColumn = "article_comments" |
||||
// TagsTable is the table the holds the tags relation/edge. The primary key declared below.
|
||||
TagsTable = "tag_posts" |
||||
// TagsInverseTable is the table name for the Tag entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "tag" package.
|
||||
TagsInverseTable = "tags" |
||||
) |
||||
|
||||
// Columns holds all SQL columns for article fields.
|
||||
var Columns = []string{ |
||||
FieldID, |
||||
FieldTitle, |
||||
FieldContent, |
||||
FieldCreatedAt, |
||||
FieldUpdatedAt, |
||||
} |
||||
|
||||
var ( |
||||
// TagsPrimaryKey and TagsColumn2 are the table columns denoting the
|
||||
// primary key for the tags relation (M2M).
|
||||
TagsPrimaryKey = []string{"tag_id", "article_id"} |
||||
) |
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool { |
||||
for i := range Columns { |
||||
if column == Columns[i] { |
||||
return true |
||||
} |
||||
} |
||||
return false |
||||
} |
||||
|
||||
var ( |
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time |
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time |
||||
) |
@ -1,584 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package article |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
) |
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
v := make([]interface{}, len(ids)) |
||||
for i := range v { |
||||
v[i] = ids[i] |
||||
} |
||||
s.Where(sql.In(s.C(FieldID), v...)) |
||||
}) |
||||
} |
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
v := make([]interface{}, len(ids)) |
||||
for i := range v { |
||||
v[i] = ids[i] |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldID), v...)) |
||||
}) |
||||
} |
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
|
||||
func Title(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
|
||||
func Content(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleEQ applies the EQ predicate on the "title" field.
|
||||
func TitleEQ(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleNEQ applies the NEQ predicate on the "title" field.
|
||||
func TitleNEQ(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleIn applies the In predicate on the "title" field.
|
||||
func TitleIn(vs ...string) predicate.Article { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldTitle), v...)) |
||||
}) |
||||
} |
||||
|
||||
// TitleNotIn applies the NotIn predicate on the "title" field.
|
||||
func TitleNotIn(vs ...string) predicate.Article { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldTitle), v...)) |
||||
}) |
||||
} |
||||
|
||||
// TitleGT applies the GT predicate on the "title" field.
|
||||
func TitleGT(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleGTE applies the GTE predicate on the "title" field.
|
||||
func TitleGTE(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleLT applies the LT predicate on the "title" field.
|
||||
func TitleLT(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleLTE applies the LTE predicate on the "title" field.
|
||||
func TitleLTE(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleContains applies the Contains predicate on the "title" field.
|
||||
func TitleContains(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.Contains(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
|
||||
func TitleHasPrefix(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.HasPrefix(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
|
||||
func TitleHasSuffix(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.HasSuffix(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleEqualFold applies the EqualFold predicate on the "title" field.
|
||||
func TitleEqualFold(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EqualFold(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
|
||||
func TitleContainsFold(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.ContainsFold(s.C(FieldTitle), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentEQ applies the EQ predicate on the "content" field.
|
||||
func ContentEQ(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentNEQ applies the NEQ predicate on the "content" field.
|
||||
func ContentNEQ(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentIn applies the In predicate on the "content" field.
|
||||
func ContentIn(vs ...string) predicate.Article { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldContent), v...)) |
||||
}) |
||||
} |
||||
|
||||
// ContentNotIn applies the NotIn predicate on the "content" field.
|
||||
func ContentNotIn(vs ...string) predicate.Article { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldContent), v...)) |
||||
}) |
||||
} |
||||
|
||||
// ContentGT applies the GT predicate on the "content" field.
|
||||
func ContentGT(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentGTE applies the GTE predicate on the "content" field.
|
||||
func ContentGTE(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentLT applies the LT predicate on the "content" field.
|
||||
func ContentLT(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentLTE applies the LTE predicate on the "content" field.
|
||||
func ContentLTE(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentContains applies the Contains predicate on the "content" field.
|
||||
func ContentContains(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.Contains(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentHasPrefix applies the HasPrefix predicate on the "content" field.
|
||||
func ContentHasPrefix(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.HasPrefix(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentHasSuffix applies the HasSuffix predicate on the "content" field.
|
||||
func ContentHasSuffix(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.HasSuffix(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentEqualFold applies the EqualFold predicate on the "content" field.
|
||||
func ContentEqualFold(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EqualFold(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentContainsFold applies the ContainsFold predicate on the "content" field.
|
||||
func ContentContainsFold(v string) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.ContainsFold(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.Article { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldCreatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.Article { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.Article { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldUpdatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.Article { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// HasComments applies the HasEdge predicate on the "comments" edge.
|
||||
func HasComments() predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(Table, FieldID), |
||||
sqlgraph.To(CommentsTable, FieldID), |
||||
sqlgraph.Edge(sqlgraph.O2M, false, CommentsTable, CommentsColumn), |
||||
) |
||||
sqlgraph.HasNeighbors(s, step) |
||||
}) |
||||
} |
||||
|
||||
// HasCommentsWith applies the HasEdge predicate on the "comments" edge with a given conditions (other predicates).
|
||||
func HasCommentsWith(preds ...predicate.Comment) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(Table, FieldID), |
||||
sqlgraph.To(CommentsInverseTable, FieldID), |
||||
sqlgraph.Edge(sqlgraph.O2M, false, CommentsTable, CommentsColumn), |
||||
) |
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { |
||||
for _, p := range preds { |
||||
p(s) |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
// HasTags applies the HasEdge predicate on the "tags" edge.
|
||||
func HasTags() predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(Table, FieldID), |
||||
sqlgraph.To(TagsTable, FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2M, true, TagsTable, TagsPrimaryKey...), |
||||
) |
||||
sqlgraph.HasNeighbors(s, step) |
||||
}) |
||||
} |
||||
|
||||
// HasTagsWith applies the HasEdge predicate on the "tags" edge with a given conditions (other predicates).
|
||||
func HasTagsWith(preds ...predicate.Tag) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(Table, FieldID), |
||||
sqlgraph.To(TagsInverseTable, FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2M, true, TagsTable, TagsPrimaryKey...), |
||||
) |
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { |
||||
for _, p := range preds { |
||||
p(s) |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Article) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s1 := s.Clone().SetP(nil) |
||||
for _, p := range predicates { |
||||
p(s1) |
||||
} |
||||
s.Where(s1.P()) |
||||
}) |
||||
} |
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Article) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
s1 := s.Clone().SetP(nil) |
||||
for i, p := range predicates { |
||||
if i > 0 { |
||||
s1.Or() |
||||
} |
||||
p(s1) |
||||
} |
||||
s.Where(s1.P()) |
||||
}) |
||||
} |
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Article) predicate.Article { |
||||
return predicate.Article(func(s *sql.Selector) { |
||||
p(s.Not()) |
||||
}) |
||||
} |
@ -1,350 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"errors" |
||||
"fmt" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" |
||||
) |
||||
|
||||
// ArticleCreate is the builder for creating a Article entity.
|
||||
type ArticleCreate struct { |
||||
config |
||||
mutation *ArticleMutation |
||||
hooks []Hook |
||||
} |
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (ac *ArticleCreate) SetTitle(s string) *ArticleCreate { |
||||
ac.mutation.SetTitle(s) |
||||
return ac |
||||
} |
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (ac *ArticleCreate) SetContent(s string) *ArticleCreate { |
||||
ac.mutation.SetContent(s) |
||||
return ac |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (ac *ArticleCreate) SetCreatedAt(t time.Time) *ArticleCreate { |
||||
ac.mutation.SetCreatedAt(t) |
||||
return ac |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (ac *ArticleCreate) SetNillableCreatedAt(t *time.Time) *ArticleCreate { |
||||
if t != nil { |
||||
ac.SetCreatedAt(*t) |
||||
} |
||||
return ac |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (ac *ArticleCreate) SetUpdatedAt(t time.Time) *ArticleCreate { |
||||
ac.mutation.SetUpdatedAt(t) |
||||
return ac |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (ac *ArticleCreate) SetNillableUpdatedAt(t *time.Time) *ArticleCreate { |
||||
if t != nil { |
||||
ac.SetUpdatedAt(*t) |
||||
} |
||||
return ac |
||||
} |
||||
|
||||
// SetID sets the "id" field.
|
||||
func (ac *ArticleCreate) SetID(i int64) *ArticleCreate { |
||||
ac.mutation.SetID(i) |
||||
return ac |
||||
} |
||||
|
||||
// AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
|
||||
func (ac *ArticleCreate) AddCommentIDs(ids ...int64) *ArticleCreate { |
||||
ac.mutation.AddCommentIDs(ids...) |
||||
return ac |
||||
} |
||||
|
||||
// AddComments adds the "comments" edges to the Comment entity.
|
||||
func (ac *ArticleCreate) AddComments(c ...*Comment) *ArticleCreate { |
||||
ids := make([]int64, len(c)) |
||||
for i := range c { |
||||
ids[i] = c[i].ID |
||||
} |
||||
return ac.AddCommentIDs(ids...) |
||||
} |
||||
|
||||
// AddTagIDs adds the "tags" edge to the Tag entity by IDs.
|
||||
func (ac *ArticleCreate) AddTagIDs(ids ...int64) *ArticleCreate { |
||||
ac.mutation.AddTagIDs(ids...) |
||||
return ac |
||||
} |
||||
|
||||
// AddTags adds the "tags" edges to the Tag entity.
|
||||
func (ac *ArticleCreate) AddTags(t ...*Tag) *ArticleCreate { |
||||
ids := make([]int64, len(t)) |
||||
for i := range t { |
||||
ids[i] = t[i].ID |
||||
} |
||||
return ac.AddTagIDs(ids...) |
||||
} |
||||
|
||||
// Mutation returns the ArticleMutation object of the builder.
|
||||
func (ac *ArticleCreate) Mutation() *ArticleMutation { |
||||
return ac.mutation |
||||
} |
||||
|
||||
// Save creates the Article in the database.
|
||||
func (ac *ArticleCreate) Save(ctx context.Context) (*Article, error) { |
||||
var ( |
||||
err error |
||||
node *Article |
||||
) |
||||
ac.defaults() |
||||
if len(ac.hooks) == 0 { |
||||
if err = ac.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
node, err = ac.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*ArticleMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
if err = ac.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
ac.mutation = mutation |
||||
node, err = ac.sqlSave(ctx) |
||||
mutation.done = true |
||||
return node, err |
||||
}) |
||||
for i := len(ac.hooks) - 1; i >= 0; i-- { |
||||
mut = ac.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, ac.mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return node, err |
||||
} |
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (ac *ArticleCreate) SaveX(ctx context.Context) *Article { |
||||
v, err := ac.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (ac *ArticleCreate) defaults() { |
||||
if _, ok := ac.mutation.CreatedAt(); !ok { |
||||
v := article.DefaultCreatedAt() |
||||
ac.mutation.SetCreatedAt(v) |
||||
} |
||||
if _, ok := ac.mutation.UpdatedAt(); !ok { |
||||
v := article.DefaultUpdatedAt() |
||||
ac.mutation.SetUpdatedAt(v) |
||||
} |
||||
} |
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ac *ArticleCreate) check() error { |
||||
if _, ok := ac.mutation.Title(); !ok { |
||||
return &ValidationError{Name: "title", err: errors.New("ent: missing required field \"title\"")} |
||||
} |
||||
if _, ok := ac.mutation.Content(); !ok { |
||||
return &ValidationError{Name: "content", err: errors.New("ent: missing required field \"content\"")} |
||||
} |
||||
if _, ok := ac.mutation.CreatedAt(); !ok { |
||||
return &ValidationError{Name: "created_at", err: errors.New("ent: missing required field \"created_at\"")} |
||||
} |
||||
if _, ok := ac.mutation.UpdatedAt(); !ok { |
||||
return &ValidationError{Name: "updated_at", err: errors.New("ent: missing required field \"updated_at\"")} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (ac *ArticleCreate) sqlSave(ctx context.Context) (*Article, error) { |
||||
_node, _spec := ac.createSpec() |
||||
if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil { |
||||
if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return nil, err |
||||
} |
||||
if _node.ID == 0 { |
||||
id := _spec.ID.Value.(int64) |
||||
_node.ID = int64(id) |
||||
} |
||||
return _node, nil |
||||
} |
||||
|
||||
func (ac *ArticleCreate) createSpec() (*Article, *sqlgraph.CreateSpec) { |
||||
var ( |
||||
_node = &Article{config: ac.config} |
||||
_spec = &sqlgraph.CreateSpec{ |
||||
Table: article.Table, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
} |
||||
) |
||||
if id, ok := ac.mutation.ID(); ok { |
||||
_node.ID = id |
||||
_spec.ID.Value = id |
||||
} |
||||
if value, ok := ac.mutation.Title(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: article.FieldTitle, |
||||
}) |
||||
_node.Title = value |
||||
} |
||||
if value, ok := ac.mutation.Content(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: article.FieldContent, |
||||
}) |
||||
_node.Content = value |
||||
} |
||||
if value, ok := ac.mutation.CreatedAt(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: article.FieldCreatedAt, |
||||
}) |
||||
_node.CreatedAt = value |
||||
} |
||||
if value, ok := ac.mutation.UpdatedAt(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: article.FieldUpdatedAt, |
||||
}) |
||||
_node.UpdatedAt = value |
||||
} |
||||
if nodes := ac.mutation.CommentsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.O2M, |
||||
Inverse: false, |
||||
Table: article.CommentsTable, |
||||
Columns: []string{article.CommentsColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges = append(_spec.Edges, edge) |
||||
} |
||||
if nodes := ac.mutation.TagsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: true, |
||||
Table: article.TagsTable, |
||||
Columns: article.TagsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges = append(_spec.Edges, edge) |
||||
} |
||||
return _node, _spec |
||||
} |
||||
|
||||
// ArticleCreateBulk is the builder for creating many Article entities in bulk.
|
||||
type ArticleCreateBulk struct { |
||||
config |
||||
builders []*ArticleCreate |
||||
} |
||||
|
||||
// Save creates the Article entities in the database.
|
||||
func (acb *ArticleCreateBulk) Save(ctx context.Context) ([]*Article, error) { |
||||
specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) |
||||
nodes := make([]*Article, len(acb.builders)) |
||||
mutators := make([]Mutator, len(acb.builders)) |
||||
for i := range acb.builders { |
||||
func(i int, root context.Context) { |
||||
builder := acb.builders[i] |
||||
builder.defaults() |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*ArticleMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
if err := builder.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
builder.mutation = mutation |
||||
nodes[i], specs[i] = builder.createSpec() |
||||
var err error |
||||
if i < len(mutators)-1 { |
||||
_, err = mutators[i+1].Mutate(root, acb.builders[i+1].mutation) |
||||
} else { |
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, acb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil { |
||||
if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
} |
||||
} |
||||
mutation.done = true |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
if nodes[i].ID == 0 { |
||||
id := specs[i].ID.Value.(int64) |
||||
nodes[i].ID = int64(id) |
||||
} |
||||
return nodes[i], nil |
||||
}) |
||||
for i := len(builder.hooks) - 1; i >= 0; i-- { |
||||
mut = builder.hooks[i](mut) |
||||
} |
||||
mutators[i] = mut |
||||
}(i, ctx) |
||||
} |
||||
if len(mutators) > 0 { |
||||
if _, err := mutators[0].Mutate(ctx, acb.builders[0].mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return nodes, nil |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (acb *ArticleCreateBulk) SaveX(ctx context.Context) []*Article { |
||||
v, err := acb.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
@ -1,108 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
) |
||||
|
||||
// ArticleDelete is the builder for deleting a Article entity.
|
||||
type ArticleDelete struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *ArticleMutation |
||||
} |
||||
|
||||
// Where adds a new predicate to the ArticleDelete builder.
|
||||
func (ad *ArticleDelete) Where(ps ...predicate.Article) *ArticleDelete { |
||||
ad.mutation.predicates = append(ad.mutation.predicates, ps...) |
||||
return ad |
||||
} |
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ad *ArticleDelete) Exec(ctx context.Context) (int, error) { |
||||
var ( |
||||
err error |
||||
affected int |
||||
) |
||||
if len(ad.hooks) == 0 { |
||||
affected, err = ad.sqlExec(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*ArticleMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
ad.mutation = mutation |
||||
affected, err = ad.sqlExec(ctx) |
||||
mutation.done = true |
||||
return affected, err |
||||
}) |
||||
for i := len(ad.hooks) - 1; i >= 0; i-- { |
||||
mut = ad.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, ad.mutation); err != nil { |
||||
return 0, err |
||||
} |
||||
} |
||||
return affected, err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ad *ArticleDelete) ExecX(ctx context.Context) int { |
||||
n, err := ad.Exec(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return n |
||||
} |
||||
|
||||
func (ad *ArticleDelete) sqlExec(ctx context.Context) (int, error) { |
||||
_spec := &sqlgraph.DeleteSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: article.Table, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
if ps := ad.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
return sqlgraph.DeleteNodes(ctx, ad.driver, _spec) |
||||
} |
||||
|
||||
// ArticleDeleteOne is the builder for deleting a single Article entity.
|
||||
type ArticleDeleteOne struct { |
||||
ad *ArticleDelete |
||||
} |
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ado *ArticleDeleteOne) Exec(ctx context.Context) error { |
||||
n, err := ado.ad.Exec(ctx) |
||||
switch { |
||||
case err != nil: |
||||
return err |
||||
case n == 0: |
||||
return &NotFoundError{article.Label} |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ado *ArticleDeleteOne) ExecX(ctx context.Context) { |
||||
ado.ad.ExecX(ctx) |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,711 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" |
||||
) |
||||
|
||||
// ArticleUpdate is the builder for updating Article entities.
|
||||
type ArticleUpdate struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *ArticleMutation |
||||
} |
||||
|
||||
// Where adds a new predicate for the ArticleUpdate builder.
|
||||
func (au *ArticleUpdate) Where(ps ...predicate.Article) *ArticleUpdate { |
||||
au.mutation.predicates = append(au.mutation.predicates, ps...) |
||||
return au |
||||
} |
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (au *ArticleUpdate) SetTitle(s string) *ArticleUpdate { |
||||
au.mutation.SetTitle(s) |
||||
return au |
||||
} |
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (au *ArticleUpdate) SetContent(s string) *ArticleUpdate { |
||||
au.mutation.SetContent(s) |
||||
return au |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (au *ArticleUpdate) SetCreatedAt(t time.Time) *ArticleUpdate { |
||||
au.mutation.SetCreatedAt(t) |
||||
return au |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (au *ArticleUpdate) SetNillableCreatedAt(t *time.Time) *ArticleUpdate { |
||||
if t != nil { |
||||
au.SetCreatedAt(*t) |
||||
} |
||||
return au |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (au *ArticleUpdate) SetUpdatedAt(t time.Time) *ArticleUpdate { |
||||
au.mutation.SetUpdatedAt(t) |
||||
return au |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (au *ArticleUpdate) SetNillableUpdatedAt(t *time.Time) *ArticleUpdate { |
||||
if t != nil { |
||||
au.SetUpdatedAt(*t) |
||||
} |
||||
return au |
||||
} |
||||
|
||||
// AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
|
||||
func (au *ArticleUpdate) AddCommentIDs(ids ...int64) *ArticleUpdate { |
||||
au.mutation.AddCommentIDs(ids...) |
||||
return au |
||||
} |
||||
|
||||
// AddComments adds the "comments" edges to the Comment entity.
|
||||
func (au *ArticleUpdate) AddComments(c ...*Comment) *ArticleUpdate { |
||||
ids := make([]int64, len(c)) |
||||
for i := range c { |
||||
ids[i] = c[i].ID |
||||
} |
||||
return au.AddCommentIDs(ids...) |
||||
} |
||||
|
||||
// AddTagIDs adds the "tags" edge to the Tag entity by IDs.
|
||||
func (au *ArticleUpdate) AddTagIDs(ids ...int64) *ArticleUpdate { |
||||
au.mutation.AddTagIDs(ids...) |
||||
return au |
||||
} |
||||
|
||||
// AddTags adds the "tags" edges to the Tag entity.
|
||||
func (au *ArticleUpdate) AddTags(t ...*Tag) *ArticleUpdate { |
||||
ids := make([]int64, len(t)) |
||||
for i := range t { |
||||
ids[i] = t[i].ID |
||||
} |
||||
return au.AddTagIDs(ids...) |
||||
} |
||||
|
||||
// Mutation returns the ArticleMutation object of the builder.
|
||||
func (au *ArticleUpdate) Mutation() *ArticleMutation { |
||||
return au.mutation |
||||
} |
||||
|
||||
// ClearComments clears all "comments" edges to the Comment entity.
|
||||
func (au *ArticleUpdate) ClearComments() *ArticleUpdate { |
||||
au.mutation.ClearComments() |
||||
return au |
||||
} |
||||
|
||||
// RemoveCommentIDs removes the "comments" edge to Comment entities by IDs.
|
||||
func (au *ArticleUpdate) RemoveCommentIDs(ids ...int64) *ArticleUpdate { |
||||
au.mutation.RemoveCommentIDs(ids...) |
||||
return au |
||||
} |
||||
|
||||
// RemoveComments removes "comments" edges to Comment entities.
|
||||
func (au *ArticleUpdate) RemoveComments(c ...*Comment) *ArticleUpdate { |
||||
ids := make([]int64, len(c)) |
||||
for i := range c { |
||||
ids[i] = c[i].ID |
||||
} |
||||
return au.RemoveCommentIDs(ids...) |
||||
} |
||||
|
||||
// ClearTags clears all "tags" edges to the Tag entity.
|
||||
func (au *ArticleUpdate) ClearTags() *ArticleUpdate { |
||||
au.mutation.ClearTags() |
||||
return au |
||||
} |
||||
|
||||
// RemoveTagIDs removes the "tags" edge to Tag entities by IDs.
|
||||
func (au *ArticleUpdate) RemoveTagIDs(ids ...int64) *ArticleUpdate { |
||||
au.mutation.RemoveTagIDs(ids...) |
||||
return au |
||||
} |
||||
|
||||
// RemoveTags removes "tags" edges to Tag entities.
|
||||
func (au *ArticleUpdate) RemoveTags(t ...*Tag) *ArticleUpdate { |
||||
ids := make([]int64, len(t)) |
||||
for i := range t { |
||||
ids[i] = t[i].ID |
||||
} |
||||
return au.RemoveTagIDs(ids...) |
||||
} |
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (au *ArticleUpdate) Save(ctx context.Context) (int, error) { |
||||
var ( |
||||
err error |
||||
affected int |
||||
) |
||||
if len(au.hooks) == 0 { |
||||
affected, err = au.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*ArticleMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
au.mutation = mutation |
||||
affected, err = au.sqlSave(ctx) |
||||
mutation.done = true |
||||
return affected, err |
||||
}) |
||||
for i := len(au.hooks) - 1; i >= 0; i-- { |
||||
mut = au.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, au.mutation); err != nil { |
||||
return 0, err |
||||
} |
||||
} |
||||
return affected, err |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (au *ArticleUpdate) SaveX(ctx context.Context) int { |
||||
affected, err := au.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return affected |
||||
} |
||||
|
||||
// Exec executes the query.
|
||||
func (au *ArticleUpdate) Exec(ctx context.Context) error { |
||||
_, err := au.Save(ctx) |
||||
return err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (au *ArticleUpdate) ExecX(ctx context.Context) { |
||||
if err := au.Exec(ctx); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
||||
|
||||
func (au *ArticleUpdate) sqlSave(ctx context.Context) (n int, err error) { |
||||
_spec := &sqlgraph.UpdateSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: article.Table, |
||||
Columns: article.Columns, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
if ps := au.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
if value, ok := au.mutation.Title(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: article.FieldTitle, |
||||
}) |
||||
} |
||||
if value, ok := au.mutation.Content(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: article.FieldContent, |
||||
}) |
||||
} |
||||
if value, ok := au.mutation.CreatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: article.FieldCreatedAt, |
||||
}) |
||||
} |
||||
if value, ok := au.mutation.UpdatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: article.FieldUpdatedAt, |
||||
}) |
||||
} |
||||
if au.mutation.CommentsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.O2M, |
||||
Inverse: false, |
||||
Table: article.CommentsTable, |
||||
Columns: []string{article.CommentsColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := au.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !au.mutation.CommentsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.O2M, |
||||
Inverse: false, |
||||
Table: article.CommentsTable, |
||||
Columns: []string{article.CommentsColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := au.mutation.CommentsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.O2M, |
||||
Inverse: false, |
||||
Table: article.CommentsTable, |
||||
Columns: []string{article.CommentsColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge) |
||||
} |
||||
if au.mutation.TagsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: true, |
||||
Table: article.TagsTable, |
||||
Columns: article.TagsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := au.mutation.RemovedTagsIDs(); len(nodes) > 0 && !au.mutation.TagsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: true, |
||||
Table: article.TagsTable, |
||||
Columns: article.TagsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := au.mutation.TagsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: true, |
||||
Table: article.TagsTable, |
||||
Columns: article.TagsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge) |
||||
} |
||||
if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { |
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
||||
err = &NotFoundError{article.Label} |
||||
} else if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return 0, err |
||||
} |
||||
return n, nil |
||||
} |
||||
|
||||
// ArticleUpdateOne is the builder for updating a single Article entity.
|
||||
type ArticleUpdateOne struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *ArticleMutation |
||||
} |
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (auo *ArticleUpdateOne) SetTitle(s string) *ArticleUpdateOne { |
||||
auo.mutation.SetTitle(s) |
||||
return auo |
||||
} |
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (auo *ArticleUpdateOne) SetContent(s string) *ArticleUpdateOne { |
||||
auo.mutation.SetContent(s) |
||||
return auo |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (auo *ArticleUpdateOne) SetCreatedAt(t time.Time) *ArticleUpdateOne { |
||||
auo.mutation.SetCreatedAt(t) |
||||
return auo |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (auo *ArticleUpdateOne) SetNillableCreatedAt(t *time.Time) *ArticleUpdateOne { |
||||
if t != nil { |
||||
auo.SetCreatedAt(*t) |
||||
} |
||||
return auo |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (auo *ArticleUpdateOne) SetUpdatedAt(t time.Time) *ArticleUpdateOne { |
||||
auo.mutation.SetUpdatedAt(t) |
||||
return auo |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (auo *ArticleUpdateOne) SetNillableUpdatedAt(t *time.Time) *ArticleUpdateOne { |
||||
if t != nil { |
||||
auo.SetUpdatedAt(*t) |
||||
} |
||||
return auo |
||||
} |
||||
|
||||
// AddCommentIDs adds the "comments" edge to the Comment entity by IDs.
|
||||
func (auo *ArticleUpdateOne) AddCommentIDs(ids ...int64) *ArticleUpdateOne { |
||||
auo.mutation.AddCommentIDs(ids...) |
||||
return auo |
||||
} |
||||
|
||||
// AddComments adds the "comments" edges to the Comment entity.
|
||||
func (auo *ArticleUpdateOne) AddComments(c ...*Comment) *ArticleUpdateOne { |
||||
ids := make([]int64, len(c)) |
||||
for i := range c { |
||||
ids[i] = c[i].ID |
||||
} |
||||
return auo.AddCommentIDs(ids...) |
||||
} |
||||
|
||||
// AddTagIDs adds the "tags" edge to the Tag entity by IDs.
|
||||
func (auo *ArticleUpdateOne) AddTagIDs(ids ...int64) *ArticleUpdateOne { |
||||
auo.mutation.AddTagIDs(ids...) |
||||
return auo |
||||
} |
||||
|
||||
// AddTags adds the "tags" edges to the Tag entity.
|
||||
func (auo *ArticleUpdateOne) AddTags(t ...*Tag) *ArticleUpdateOne { |
||||
ids := make([]int64, len(t)) |
||||
for i := range t { |
||||
ids[i] = t[i].ID |
||||
} |
||||
return auo.AddTagIDs(ids...) |
||||
} |
||||
|
||||
// Mutation returns the ArticleMutation object of the builder.
|
||||
func (auo *ArticleUpdateOne) Mutation() *ArticleMutation { |
||||
return auo.mutation |
||||
} |
||||
|
||||
// ClearComments clears all "comments" edges to the Comment entity.
|
||||
func (auo *ArticleUpdateOne) ClearComments() *ArticleUpdateOne { |
||||
auo.mutation.ClearComments() |
||||
return auo |
||||
} |
||||
|
||||
// RemoveCommentIDs removes the "comments" edge to Comment entities by IDs.
|
||||
func (auo *ArticleUpdateOne) RemoveCommentIDs(ids ...int64) *ArticleUpdateOne { |
||||
auo.mutation.RemoveCommentIDs(ids...) |
||||
return auo |
||||
} |
||||
|
||||
// RemoveComments removes "comments" edges to Comment entities.
|
||||
func (auo *ArticleUpdateOne) RemoveComments(c ...*Comment) *ArticleUpdateOne { |
||||
ids := make([]int64, len(c)) |
||||
for i := range c { |
||||
ids[i] = c[i].ID |
||||
} |
||||
return auo.RemoveCommentIDs(ids...) |
||||
} |
||||
|
||||
// ClearTags clears all "tags" edges to the Tag entity.
|
||||
func (auo *ArticleUpdateOne) ClearTags() *ArticleUpdateOne { |
||||
auo.mutation.ClearTags() |
||||
return auo |
||||
} |
||||
|
||||
// RemoveTagIDs removes the "tags" edge to Tag entities by IDs.
|
||||
func (auo *ArticleUpdateOne) RemoveTagIDs(ids ...int64) *ArticleUpdateOne { |
||||
auo.mutation.RemoveTagIDs(ids...) |
||||
return auo |
||||
} |
||||
|
||||
// RemoveTags removes "tags" edges to Tag entities.
|
||||
func (auo *ArticleUpdateOne) RemoveTags(t ...*Tag) *ArticleUpdateOne { |
||||
ids := make([]int64, len(t)) |
||||
for i := range t { |
||||
ids[i] = t[i].ID |
||||
} |
||||
return auo.RemoveTagIDs(ids...) |
||||
} |
||||
|
||||
// Save executes the query and returns the updated Article entity.
|
||||
func (auo *ArticleUpdateOne) Save(ctx context.Context) (*Article, error) { |
||||
var ( |
||||
err error |
||||
node *Article |
||||
) |
||||
if len(auo.hooks) == 0 { |
||||
node, err = auo.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*ArticleMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
auo.mutation = mutation |
||||
node, err = auo.sqlSave(ctx) |
||||
mutation.done = true |
||||
return node, err |
||||
}) |
||||
for i := len(auo.hooks) - 1; i >= 0; i-- { |
||||
mut = auo.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, auo.mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return node, err |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (auo *ArticleUpdateOne) SaveX(ctx context.Context) *Article { |
||||
node, err := auo.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return node |
||||
} |
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (auo *ArticleUpdateOne) Exec(ctx context.Context) error { |
||||
_, err := auo.Save(ctx) |
||||
return err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (auo *ArticleUpdateOne) ExecX(ctx context.Context) { |
||||
if err := auo.Exec(ctx); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
||||
|
||||
func (auo *ArticleUpdateOne) sqlSave(ctx context.Context) (_node *Article, err error) { |
||||
_spec := &sqlgraph.UpdateSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: article.Table, |
||||
Columns: article.Columns, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
id, ok := auo.mutation.ID() |
||||
if !ok { |
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Article.ID for update")} |
||||
} |
||||
_spec.Node.ID.Value = id |
||||
if ps := auo.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
if value, ok := auo.mutation.Title(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: article.FieldTitle, |
||||
}) |
||||
} |
||||
if value, ok := auo.mutation.Content(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: article.FieldContent, |
||||
}) |
||||
} |
||||
if value, ok := auo.mutation.CreatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: article.FieldCreatedAt, |
||||
}) |
||||
} |
||||
if value, ok := auo.mutation.UpdatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: article.FieldUpdatedAt, |
||||
}) |
||||
} |
||||
if auo.mutation.CommentsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.O2M, |
||||
Inverse: false, |
||||
Table: article.CommentsTable, |
||||
Columns: []string{article.CommentsColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := auo.mutation.RemovedCommentsIDs(); len(nodes) > 0 && !auo.mutation.CommentsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.O2M, |
||||
Inverse: false, |
||||
Table: article.CommentsTable, |
||||
Columns: []string{article.CommentsColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := auo.mutation.CommentsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.O2M, |
||||
Inverse: false, |
||||
Table: article.CommentsTable, |
||||
Columns: []string{article.CommentsColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge) |
||||
} |
||||
if auo.mutation.TagsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: true, |
||||
Table: article.TagsTable, |
||||
Columns: article.TagsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := auo.mutation.RemovedTagsIDs(); len(nodes) > 0 && !auo.mutation.TagsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: true, |
||||
Table: article.TagsTable, |
||||
Columns: article.TagsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := auo.mutation.TagsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: true, |
||||
Table: article.TagsTable, |
||||
Columns: article.TagsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge) |
||||
} |
||||
_node = &Article{config: auo.config} |
||||
_spec.Assign = _node.assignValues |
||||
_spec.ScanValues = _node.scanValues |
||||
if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { |
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
||||
err = &NotFoundError{article.Label} |
||||
} else if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return nil, err |
||||
} |
||||
return _node, nil |
||||
} |
@ -1,465 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"log" |
||||
|
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/migrate" |
||||
|
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" |
||||
|
||||
"entgo.io/ent/dialect" |
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
) |
||||
|
||||
// Client is the client that holds all ent builders.
|
||||
type Client struct { |
||||
config |
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema |
||||
// Article is the client for interacting with the Article builders.
|
||||
Article *ArticleClient |
||||
// Comment is the client for interacting with the Comment builders.
|
||||
Comment *CommentClient |
||||
// Tag is the client for interacting with the Tag builders.
|
||||
Tag *TagClient |
||||
} |
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
func NewClient(opts ...Option) *Client { |
||||
cfg := config{log: log.Println, hooks: &hooks{}} |
||||
cfg.options(opts...) |
||||
client := &Client{config: cfg} |
||||
client.init() |
||||
return client |
||||
} |
||||
|
||||
func (c *Client) init() { |
||||
c.Schema = migrate.NewSchema(c.driver) |
||||
c.Article = NewArticleClient(c.config) |
||||
c.Comment = NewCommentClient(c.config) |
||||
c.Tag = NewTagClient(c.config) |
||||
} |
||||
|
||||
// Open opens a database/sql.DB specified by the driver name and
|
||||
// the data source name, and returns a new client attached to it.
|
||||
// Optional parameters can be added for configuring the client.
|
||||
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { |
||||
switch driverName { |
||||
case dialect.MySQL, dialect.Postgres, dialect.SQLite: |
||||
drv, err := sql.Open(driverName, dataSourceName) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return NewClient(append(options, Driver(drv))...), nil |
||||
default: |
||||
return nil, fmt.Errorf("unsupported driver: %q", driverName) |
||||
} |
||||
} |
||||
|
||||
// Tx returns a new transactional client. The provided context
|
||||
// is used until the transaction is committed or rolled back.
|
||||
func (c *Client) Tx(ctx context.Context) (*Tx, error) { |
||||
if _, ok := c.driver.(*txDriver); ok { |
||||
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") |
||||
} |
||||
tx, err := newTx(ctx, c.driver) |
||||
if err != nil { |
||||
return nil, fmt.Errorf("ent: starting a transaction: %v", err) |
||||
} |
||||
cfg := c.config |
||||
cfg.driver = tx |
||||
return &Tx{ |
||||
ctx: ctx, |
||||
config: cfg, |
||||
Article: NewArticleClient(cfg), |
||||
Comment: NewCommentClient(cfg), |
||||
Tag: NewTagClient(cfg), |
||||
}, nil |
||||
} |
||||
|
||||
// BeginTx returns a transactional client with specified options.
|
||||
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { |
||||
if _, ok := c.driver.(*txDriver); ok { |
||||
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") |
||||
} |
||||
tx, err := c.driver.(interface { |
||||
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) |
||||
}).BeginTx(ctx, opts) |
||||
if err != nil { |
||||
return nil, fmt.Errorf("ent: starting a transaction: %v", err) |
||||
} |
||||
cfg := c.config |
||||
cfg.driver = &txDriver{tx: tx, drv: c.driver} |
||||
return &Tx{ |
||||
config: cfg, |
||||
Article: NewArticleClient(cfg), |
||||
Comment: NewCommentClient(cfg), |
||||
Tag: NewTagClient(cfg), |
||||
}, nil |
||||
} |
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// Article.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
//
|
||||
func (c *Client) Debug() *Client { |
||||
if c.debug { |
||||
return c |
||||
} |
||||
cfg := c.config |
||||
cfg.driver = dialect.Debug(c.driver, c.log) |
||||
client := &Client{config: cfg} |
||||
client.init() |
||||
return client |
||||
} |
||||
|
||||
// Close closes the database connection and prevents new queries from starting.
|
||||
func (c *Client) Close() error { |
||||
return c.driver.Close() |
||||
} |
||||
|
||||
// Use adds the mutation hooks to all the entity clients.
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) { |
||||
c.Article.Use(hooks...) |
||||
c.Comment.Use(hooks...) |
||||
c.Tag.Use(hooks...) |
||||
} |
||||
|
||||
// ArticleClient is a client for the Article schema.
|
||||
type ArticleClient struct { |
||||
config |
||||
} |
||||
|
||||
// NewArticleClient returns a client for the Article from the given config.
|
||||
func NewArticleClient(c config) *ArticleClient { |
||||
return &ArticleClient{config: c} |
||||
} |
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `article.Hooks(f(g(h())))`.
|
||||
func (c *ArticleClient) Use(hooks ...Hook) { |
||||
c.hooks.Article = append(c.hooks.Article, hooks...) |
||||
} |
||||
|
||||
// Create returns a create builder for Article.
|
||||
func (c *ArticleClient) Create() *ArticleCreate { |
||||
mutation := newArticleMutation(c.config, OpCreate) |
||||
return &ArticleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Article entities.
|
||||
func (c *ArticleClient) CreateBulk(builders ...*ArticleCreate) *ArticleCreateBulk { |
||||
return &ArticleCreateBulk{config: c.config, builders: builders} |
||||
} |
||||
|
||||
// Update returns an update builder for Article.
|
||||
func (c *ArticleClient) Update() *ArticleUpdate { |
||||
mutation := newArticleMutation(c.config, OpUpdate) |
||||
return &ArticleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *ArticleClient) UpdateOne(a *Article) *ArticleUpdateOne { |
||||
mutation := newArticleMutation(c.config, OpUpdateOne, withArticle(a)) |
||||
return &ArticleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *ArticleClient) UpdateOneID(id int64) *ArticleUpdateOne { |
||||
mutation := newArticleMutation(c.config, OpUpdateOne, withArticleID(id)) |
||||
return &ArticleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// Delete returns a delete builder for Article.
|
||||
func (c *ArticleClient) Delete() *ArticleDelete { |
||||
mutation := newArticleMutation(c.config, OpDelete) |
||||
return &ArticleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *ArticleClient) DeleteOne(a *Article) *ArticleDeleteOne { |
||||
return c.DeleteOneID(a.ID) |
||||
} |
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *ArticleClient) DeleteOneID(id int64) *ArticleDeleteOne { |
||||
builder := c.Delete().Where(article.ID(id)) |
||||
builder.mutation.id = &id |
||||
builder.mutation.op = OpDeleteOne |
||||
return &ArticleDeleteOne{builder} |
||||
} |
||||
|
||||
// Query returns a query builder for Article.
|
||||
func (c *ArticleClient) Query() *ArticleQuery { |
||||
return &ArticleQuery{config: c.config} |
||||
} |
||||
|
||||
// Get returns a Article entity by its id.
|
||||
func (c *ArticleClient) Get(ctx context.Context, id int64) (*Article, error) { |
||||
return c.Query().Where(article.ID(id)).Only(ctx) |
||||
} |
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *ArticleClient) GetX(ctx context.Context, id int64) *Article { |
||||
obj, err := c.Get(ctx, id) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return obj |
||||
} |
||||
|
||||
// QueryComments queries the comments edge of a Article.
|
||||
func (c *ArticleClient) QueryComments(a *Article) *CommentQuery { |
||||
query := &CommentQuery{config: c.config} |
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { |
||||
id := a.ID |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(article.Table, article.FieldID, id), |
||||
sqlgraph.To(comment.Table, comment.FieldID), |
||||
sqlgraph.Edge(sqlgraph.O2M, false, article.CommentsTable, article.CommentsColumn), |
||||
) |
||||
fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) |
||||
return fromV, nil |
||||
} |
||||
return query |
||||
} |
||||
|
||||
// QueryTags queries the tags edge of a Article.
|
||||
func (c *ArticleClient) QueryTags(a *Article) *TagQuery { |
||||
query := &TagQuery{config: c.config} |
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { |
||||
id := a.ID |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(article.Table, article.FieldID, id), |
||||
sqlgraph.To(tag.Table, tag.FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2M, true, article.TagsTable, article.TagsPrimaryKey...), |
||||
) |
||||
fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) |
||||
return fromV, nil |
||||
} |
||||
return query |
||||
} |
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *ArticleClient) Hooks() []Hook { |
||||
return c.hooks.Article |
||||
} |
||||
|
||||
// CommentClient is a client for the Comment schema.
|
||||
type CommentClient struct { |
||||
config |
||||
} |
||||
|
||||
// NewCommentClient returns a client for the Comment from the given config.
|
||||
func NewCommentClient(c config) *CommentClient { |
||||
return &CommentClient{config: c} |
||||
} |
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `comment.Hooks(f(g(h())))`.
|
||||
func (c *CommentClient) Use(hooks ...Hook) { |
||||
c.hooks.Comment = append(c.hooks.Comment, hooks...) |
||||
} |
||||
|
||||
// Create returns a create builder for Comment.
|
||||
func (c *CommentClient) Create() *CommentCreate { |
||||
mutation := newCommentMutation(c.config, OpCreate) |
||||
return &CommentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Comment entities.
|
||||
func (c *CommentClient) CreateBulk(builders ...*CommentCreate) *CommentCreateBulk { |
||||
return &CommentCreateBulk{config: c.config, builders: builders} |
||||
} |
||||
|
||||
// Update returns an update builder for Comment.
|
||||
func (c *CommentClient) Update() *CommentUpdate { |
||||
mutation := newCommentMutation(c.config, OpUpdate) |
||||
return &CommentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *CommentClient) UpdateOne(co *Comment) *CommentUpdateOne { |
||||
mutation := newCommentMutation(c.config, OpUpdateOne, withComment(co)) |
||||
return &CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *CommentClient) UpdateOneID(id int64) *CommentUpdateOne { |
||||
mutation := newCommentMutation(c.config, OpUpdateOne, withCommentID(id)) |
||||
return &CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// Delete returns a delete builder for Comment.
|
||||
func (c *CommentClient) Delete() *CommentDelete { |
||||
mutation := newCommentMutation(c.config, OpDelete) |
||||
return &CommentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *CommentClient) DeleteOne(co *Comment) *CommentDeleteOne { |
||||
return c.DeleteOneID(co.ID) |
||||
} |
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *CommentClient) DeleteOneID(id int64) *CommentDeleteOne { |
||||
builder := c.Delete().Where(comment.ID(id)) |
||||
builder.mutation.id = &id |
||||
builder.mutation.op = OpDeleteOne |
||||
return &CommentDeleteOne{builder} |
||||
} |
||||
|
||||
// Query returns a query builder for Comment.
|
||||
func (c *CommentClient) Query() *CommentQuery { |
||||
return &CommentQuery{config: c.config} |
||||
} |
||||
|
||||
// Get returns a Comment entity by its id.
|
||||
func (c *CommentClient) Get(ctx context.Context, id int64) (*Comment, error) { |
||||
return c.Query().Where(comment.ID(id)).Only(ctx) |
||||
} |
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *CommentClient) GetX(ctx context.Context, id int64) *Comment { |
||||
obj, err := c.Get(ctx, id) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return obj |
||||
} |
||||
|
||||
// QueryPost queries the post edge of a Comment.
|
||||
func (c *CommentClient) QueryPost(co *Comment) *ArticleQuery { |
||||
query := &ArticleQuery{config: c.config} |
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { |
||||
id := co.ID |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(comment.Table, comment.FieldID, id), |
||||
sqlgraph.To(article.Table, article.FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2O, true, comment.PostTable, comment.PostColumn), |
||||
) |
||||
fromV = sqlgraph.Neighbors(co.driver.Dialect(), step) |
||||
return fromV, nil |
||||
} |
||||
return query |
||||
} |
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *CommentClient) Hooks() []Hook { |
||||
return c.hooks.Comment |
||||
} |
||||
|
||||
// TagClient is a client for the Tag schema.
|
||||
type TagClient struct { |
||||
config |
||||
} |
||||
|
||||
// NewTagClient returns a client for the Tag from the given config.
|
||||
func NewTagClient(c config) *TagClient { |
||||
return &TagClient{config: c} |
||||
} |
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `tag.Hooks(f(g(h())))`.
|
||||
func (c *TagClient) Use(hooks ...Hook) { |
||||
c.hooks.Tag = append(c.hooks.Tag, hooks...) |
||||
} |
||||
|
||||
// Create returns a create builder for Tag.
|
||||
func (c *TagClient) Create() *TagCreate { |
||||
mutation := newTagMutation(c.config, OpCreate) |
||||
return &TagCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Tag entities.
|
||||
func (c *TagClient) CreateBulk(builders ...*TagCreate) *TagCreateBulk { |
||||
return &TagCreateBulk{config: c.config, builders: builders} |
||||
} |
||||
|
||||
// Update returns an update builder for Tag.
|
||||
func (c *TagClient) Update() *TagUpdate { |
||||
mutation := newTagMutation(c.config, OpUpdate) |
||||
return &TagUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *TagClient) UpdateOne(t *Tag) *TagUpdateOne { |
||||
mutation := newTagMutation(c.config, OpUpdateOne, withTag(t)) |
||||
return &TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *TagClient) UpdateOneID(id int64) *TagUpdateOne { |
||||
mutation := newTagMutation(c.config, OpUpdateOne, withTagID(id)) |
||||
return &TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// Delete returns a delete builder for Tag.
|
||||
func (c *TagClient) Delete() *TagDelete { |
||||
mutation := newTagMutation(c.config, OpDelete) |
||||
return &TagDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} |
||||
} |
||||
|
||||
// DeleteOne returns a delete builder for the given entity.
|
||||
func (c *TagClient) DeleteOne(t *Tag) *TagDeleteOne { |
||||
return c.DeleteOneID(t.ID) |
||||
} |
||||
|
||||
// DeleteOneID returns a delete builder for the given id.
|
||||
func (c *TagClient) DeleteOneID(id int64) *TagDeleteOne { |
||||
builder := c.Delete().Where(tag.ID(id)) |
||||
builder.mutation.id = &id |
||||
builder.mutation.op = OpDeleteOne |
||||
return &TagDeleteOne{builder} |
||||
} |
||||
|
||||
// Query returns a query builder for Tag.
|
||||
func (c *TagClient) Query() *TagQuery { |
||||
return &TagQuery{config: c.config} |
||||
} |
||||
|
||||
// Get returns a Tag entity by its id.
|
||||
func (c *TagClient) Get(ctx context.Context, id int64) (*Tag, error) { |
||||
return c.Query().Where(tag.ID(id)).Only(ctx) |
||||
} |
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *TagClient) GetX(ctx context.Context, id int64) *Tag { |
||||
obj, err := c.Get(ctx, id) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return obj |
||||
} |
||||
|
||||
// QueryPosts queries the posts edge of a Tag.
|
||||
func (c *TagClient) QueryPosts(t *Tag) *ArticleQuery { |
||||
query := &ArticleQuery{config: c.config} |
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { |
||||
id := t.ID |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(tag.Table, tag.FieldID, id), |
||||
sqlgraph.To(article.Table, article.FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2M, false, tag.PostsTable, tag.PostsPrimaryKey...), |
||||
) |
||||
fromV = sqlgraph.Neighbors(t.driver.Dialect(), step) |
||||
return fromV, nil |
||||
} |
||||
return query |
||||
} |
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *TagClient) Hooks() []Hook { |
||||
return c.hooks.Tag |
||||
} |
@ -1,174 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strings" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
) |
||||
|
||||
// Comment is the model entity for the Comment schema.
|
||||
type Comment struct { |
||||
config `json:"-"` |
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"` |
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"` |
||||
// Content holds the value of the "content" field.
|
||||
Content string `json:"content,omitempty"` |
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"` |
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"` |
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the CommentQuery when eager-loading is set.
|
||||
Edges CommentEdges `json:"edges"` |
||||
article_comments *int64 |
||||
} |
||||
|
||||
// CommentEdges holds the relations/edges for other nodes in the graph.
|
||||
type CommentEdges struct { |
||||
// Post holds the value of the post edge.
|
||||
Post *Article `json:"post,omitempty"` |
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool |
||||
} |
||||
|
||||
// PostOrErr returns the Post value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e CommentEdges) PostOrErr() (*Article, error) { |
||||
if e.loadedTypes[0] { |
||||
if e.Post == nil { |
||||
// The edge post was loaded in eager-loading,
|
||||
// but was not found.
|
||||
return nil, &NotFoundError{label: article.Label} |
||||
} |
||||
return e.Post, nil |
||||
} |
||||
return nil, &NotLoadedError{edge: "post"} |
||||
} |
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Comment) scanValues(columns []string) ([]interface{}, error) { |
||||
values := make([]interface{}, len(columns)) |
||||
for i := range columns { |
||||
switch columns[i] { |
||||
case comment.FieldID: |
||||
values[i] = &sql.NullInt64{} |
||||
case comment.FieldName, comment.FieldContent: |
||||
values[i] = &sql.NullString{} |
||||
case comment.FieldCreatedAt, comment.FieldUpdatedAt: |
||||
values[i] = &sql.NullTime{} |
||||
case comment.ForeignKeys[0]: // article_comments
|
||||
values[i] = &sql.NullInt64{} |
||||
default: |
||||
return nil, fmt.Errorf("unexpected column %q for type Comment", columns[i]) |
||||
} |
||||
} |
||||
return values, nil |
||||
} |
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Comment fields.
|
||||
func (c *Comment) assignValues(columns []string, values []interface{}) error { |
||||
if m, n := len(values), len(columns); m < n { |
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) |
||||
} |
||||
for i := range columns { |
||||
switch columns[i] { |
||||
case comment.FieldID: |
||||
value, ok := values[i].(*sql.NullInt64) |
||||
if !ok { |
||||
return fmt.Errorf("unexpected type %T for field id", value) |
||||
} |
||||
c.ID = int64(value.Int64) |
||||
case comment.FieldName: |
||||
if value, ok := values[i].(*sql.NullString); !ok { |
||||
return fmt.Errorf("unexpected type %T for field name", values[i]) |
||||
} else if value.Valid { |
||||
c.Name = value.String |
||||
} |
||||
case comment.FieldContent: |
||||
if value, ok := values[i].(*sql.NullString); !ok { |
||||
return fmt.Errorf("unexpected type %T for field content", values[i]) |
||||
} else if value.Valid { |
||||
c.Content = value.String |
||||
} |
||||
case comment.FieldCreatedAt: |
||||
if value, ok := values[i].(*sql.NullTime); !ok { |
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i]) |
||||
} else if value.Valid { |
||||
c.CreatedAt = value.Time |
||||
} |
||||
case comment.FieldUpdatedAt: |
||||
if value, ok := values[i].(*sql.NullTime); !ok { |
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i]) |
||||
} else if value.Valid { |
||||
c.UpdatedAt = value.Time |
||||
} |
||||
case comment.ForeignKeys[0]: |
||||
if value, ok := values[i].(*sql.NullInt64); !ok { |
||||
return fmt.Errorf("unexpected type %T for edge-field article_comments", value) |
||||
} else if value.Valid { |
||||
c.article_comments = new(int64) |
||||
*c.article_comments = int64(value.Int64) |
||||
} |
||||
} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// QueryPost queries the "post" edge of the Comment entity.
|
||||
func (c *Comment) QueryPost() *ArticleQuery { |
||||
return (&CommentClient{config: c.config}).QueryPost(c) |
||||
} |
||||
|
||||
// Update returns a builder for updating this Comment.
|
||||
// Note that you need to call Comment.Unwrap() before calling this method if this Comment
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (c *Comment) Update() *CommentUpdateOne { |
||||
return (&CommentClient{config: c.config}).UpdateOne(c) |
||||
} |
||||
|
||||
// Unwrap unwraps the Comment entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (c *Comment) Unwrap() *Comment { |
||||
tx, ok := c.config.driver.(*txDriver) |
||||
if !ok { |
||||
panic("ent: Comment is not a transactional entity") |
||||
} |
||||
c.config.driver = tx.drv |
||||
return c |
||||
} |
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (c *Comment) String() string { |
||||
var builder strings.Builder |
||||
builder.WriteString("Comment(") |
||||
builder.WriteString(fmt.Sprintf("id=%v", c.ID)) |
||||
builder.WriteString(", name=") |
||||
builder.WriteString(c.Name) |
||||
builder.WriteString(", content=") |
||||
builder.WriteString(c.Content) |
||||
builder.WriteString(", created_at=") |
||||
builder.WriteString(c.CreatedAt.Format(time.ANSIC)) |
||||
builder.WriteString(", updated_at=") |
||||
builder.WriteString(c.UpdatedAt.Format(time.ANSIC)) |
||||
builder.WriteByte(')') |
||||
return builder.String() |
||||
} |
||||
|
||||
// Comments is a parsable slice of Comment.
|
||||
type Comments []*Comment |
||||
|
||||
func (c Comments) config(cfg config) { |
||||
for _i := range c { |
||||
c[_i].config = cfg |
||||
} |
||||
} |
@ -1,71 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package comment |
||||
|
||||
import ( |
||||
"time" |
||||
) |
||||
|
||||
const ( |
||||
// Label holds the string label denoting the comment type in the database.
|
||||
Label = "comment" |
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id" |
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name" |
||||
// FieldContent holds the string denoting the content field in the database.
|
||||
FieldContent = "content" |
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at" |
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at" |
||||
|
||||
// EdgePost holds the string denoting the post edge name in mutations.
|
||||
EdgePost = "post" |
||||
|
||||
// Table holds the table name of the comment in the database.
|
||||
Table = "comments" |
||||
// PostTable is the table the holds the post relation/edge.
|
||||
PostTable = "comments" |
||||
// PostInverseTable is the table name for the Article entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "article" package.
|
||||
PostInverseTable = "articles" |
||||
// PostColumn is the table column denoting the post relation/edge.
|
||||
PostColumn = "article_comments" |
||||
) |
||||
|
||||
// Columns holds all SQL columns for comment fields.
|
||||
var Columns = []string{ |
||||
FieldID, |
||||
FieldName, |
||||
FieldContent, |
||||
FieldCreatedAt, |
||||
FieldUpdatedAt, |
||||
} |
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the Comment type.
|
||||
var ForeignKeys = []string{ |
||||
"article_comments", |
||||
} |
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool { |
||||
for i := range Columns { |
||||
if column == Columns[i] { |
||||
return true |
||||
} |
||||
} |
||||
for i := range ForeignKeys { |
||||
if column == ForeignKeys[i] { |
||||
return true |
||||
} |
||||
} |
||||
return false |
||||
} |
||||
|
||||
var ( |
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time |
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time |
||||
) |
@ -1,556 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package comment |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
) |
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
v := make([]interface{}, len(ids)) |
||||
for i := range v { |
||||
v[i] = ids[i] |
||||
} |
||||
s.Where(sql.In(s.C(FieldID), v...)) |
||||
}) |
||||
} |
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
v := make([]interface{}, len(ids)) |
||||
for i := range v { |
||||
v[i] = ids[i] |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldID), v...)) |
||||
}) |
||||
} |
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// Content applies equality check predicate on the "content" field. It's identical to ContentEQ.
|
||||
func Content(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Comment { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldName), v...)) |
||||
}) |
||||
} |
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Comment { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldName), v...)) |
||||
}) |
||||
} |
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.Contains(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.HasPrefix(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.HasSuffix(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EqualFold(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.ContainsFold(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentEQ applies the EQ predicate on the "content" field.
|
||||
func ContentEQ(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentNEQ applies the NEQ predicate on the "content" field.
|
||||
func ContentNEQ(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentIn applies the In predicate on the "content" field.
|
||||
func ContentIn(vs ...string) predicate.Comment { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldContent), v...)) |
||||
}) |
||||
} |
||||
|
||||
// ContentNotIn applies the NotIn predicate on the "content" field.
|
||||
func ContentNotIn(vs ...string) predicate.Comment { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldContent), v...)) |
||||
}) |
||||
} |
||||
|
||||
// ContentGT applies the GT predicate on the "content" field.
|
||||
func ContentGT(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentGTE applies the GTE predicate on the "content" field.
|
||||
func ContentGTE(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentLT applies the LT predicate on the "content" field.
|
||||
func ContentLT(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentLTE applies the LTE predicate on the "content" field.
|
||||
func ContentLTE(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentContains applies the Contains predicate on the "content" field.
|
||||
func ContentContains(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.Contains(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentHasPrefix applies the HasPrefix predicate on the "content" field.
|
||||
func ContentHasPrefix(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.HasPrefix(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentHasSuffix applies the HasSuffix predicate on the "content" field.
|
||||
func ContentHasSuffix(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.HasSuffix(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentEqualFold applies the EqualFold predicate on the "content" field.
|
||||
func ContentEqualFold(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EqualFold(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// ContentContainsFold applies the ContainsFold predicate on the "content" field.
|
||||
func ContentContainsFold(v string) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.ContainsFold(s.C(FieldContent), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.Comment { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldCreatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.Comment { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.Comment { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldUpdatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.Comment { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// HasPost applies the HasEdge predicate on the "post" edge.
|
||||
func HasPost() predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(Table, FieldID), |
||||
sqlgraph.To(PostTable, FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2O, true, PostTable, PostColumn), |
||||
) |
||||
sqlgraph.HasNeighbors(s, step) |
||||
}) |
||||
} |
||||
|
||||
// HasPostWith applies the HasEdge predicate on the "post" edge with a given conditions (other predicates).
|
||||
func HasPostWith(preds ...predicate.Article) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(Table, FieldID), |
||||
sqlgraph.To(PostInverseTable, FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2O, true, PostTable, PostColumn), |
||||
) |
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { |
||||
for _, p := range preds { |
||||
p(s) |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Comment) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s1 := s.Clone().SetP(nil) |
||||
for _, p := range predicates { |
||||
p(s1) |
||||
} |
||||
s.Where(s1.P()) |
||||
}) |
||||
} |
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Comment) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
s1 := s.Clone().SetP(nil) |
||||
for i, p := range predicates { |
||||
if i > 0 { |
||||
s1.Or() |
||||
} |
||||
p(s1) |
||||
} |
||||
s.Where(s1.P()) |
||||
}) |
||||
} |
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Comment) predicate.Comment { |
||||
return predicate.Comment(func(s *sql.Selector) { |
||||
p(s.Not()) |
||||
}) |
||||
} |
@ -1,319 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"errors" |
||||
"fmt" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
) |
||||
|
||||
// CommentCreate is the builder for creating a Comment entity.
|
||||
type CommentCreate struct { |
||||
config |
||||
mutation *CommentMutation |
||||
hooks []Hook |
||||
} |
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cc *CommentCreate) SetName(s string) *CommentCreate { |
||||
cc.mutation.SetName(s) |
||||
return cc |
||||
} |
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (cc *CommentCreate) SetContent(s string) *CommentCreate { |
||||
cc.mutation.SetContent(s) |
||||
return cc |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (cc *CommentCreate) SetCreatedAt(t time.Time) *CommentCreate { |
||||
cc.mutation.SetCreatedAt(t) |
||||
return cc |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (cc *CommentCreate) SetNillableCreatedAt(t *time.Time) *CommentCreate { |
||||
if t != nil { |
||||
cc.SetCreatedAt(*t) |
||||
} |
||||
return cc |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (cc *CommentCreate) SetUpdatedAt(t time.Time) *CommentCreate { |
||||
cc.mutation.SetUpdatedAt(t) |
||||
return cc |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (cc *CommentCreate) SetNillableUpdatedAt(t *time.Time) *CommentCreate { |
||||
if t != nil { |
||||
cc.SetUpdatedAt(*t) |
||||
} |
||||
return cc |
||||
} |
||||
|
||||
// SetID sets the "id" field.
|
||||
func (cc *CommentCreate) SetID(i int64) *CommentCreate { |
||||
cc.mutation.SetID(i) |
||||
return cc |
||||
} |
||||
|
||||
// SetPostID sets the "post" edge to the Article entity by ID.
|
||||
func (cc *CommentCreate) SetPostID(id int64) *CommentCreate { |
||||
cc.mutation.SetPostID(id) |
||||
return cc |
||||
} |
||||
|
||||
// SetNillablePostID sets the "post" edge to the Article entity by ID if the given value is not nil.
|
||||
func (cc *CommentCreate) SetNillablePostID(id *int64) *CommentCreate { |
||||
if id != nil { |
||||
cc = cc.SetPostID(*id) |
||||
} |
||||
return cc |
||||
} |
||||
|
||||
// SetPost sets the "post" edge to the Article entity.
|
||||
func (cc *CommentCreate) SetPost(a *Article) *CommentCreate { |
||||
return cc.SetPostID(a.ID) |
||||
} |
||||
|
||||
// Mutation returns the CommentMutation object of the builder.
|
||||
func (cc *CommentCreate) Mutation() *CommentMutation { |
||||
return cc.mutation |
||||
} |
||||
|
||||
// Save creates the Comment in the database.
|
||||
func (cc *CommentCreate) Save(ctx context.Context) (*Comment, error) { |
||||
var ( |
||||
err error |
||||
node *Comment |
||||
) |
||||
cc.defaults() |
||||
if len(cc.hooks) == 0 { |
||||
if err = cc.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
node, err = cc.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*CommentMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
if err = cc.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
cc.mutation = mutation |
||||
node, err = cc.sqlSave(ctx) |
||||
mutation.done = true |
||||
return node, err |
||||
}) |
||||
for i := len(cc.hooks) - 1; i >= 0; i-- { |
||||
mut = cc.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, cc.mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return node, err |
||||
} |
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (cc *CommentCreate) SaveX(ctx context.Context) *Comment { |
||||
v, err := cc.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (cc *CommentCreate) defaults() { |
||||
if _, ok := cc.mutation.CreatedAt(); !ok { |
||||
v := comment.DefaultCreatedAt() |
||||
cc.mutation.SetCreatedAt(v) |
||||
} |
||||
if _, ok := cc.mutation.UpdatedAt(); !ok { |
||||
v := comment.DefaultUpdatedAt() |
||||
cc.mutation.SetUpdatedAt(v) |
||||
} |
||||
} |
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cc *CommentCreate) check() error { |
||||
if _, ok := cc.mutation.Name(); !ok { |
||||
return &ValidationError{Name: "name", err: errors.New("ent: missing required field \"name\"")} |
||||
} |
||||
if _, ok := cc.mutation.Content(); !ok { |
||||
return &ValidationError{Name: "content", err: errors.New("ent: missing required field \"content\"")} |
||||
} |
||||
if _, ok := cc.mutation.CreatedAt(); !ok { |
||||
return &ValidationError{Name: "created_at", err: errors.New("ent: missing required field \"created_at\"")} |
||||
} |
||||
if _, ok := cc.mutation.UpdatedAt(); !ok { |
||||
return &ValidationError{Name: "updated_at", err: errors.New("ent: missing required field \"updated_at\"")} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (cc *CommentCreate) sqlSave(ctx context.Context) (*Comment, error) { |
||||
_node, _spec := cc.createSpec() |
||||
if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil { |
||||
if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return nil, err |
||||
} |
||||
if _node.ID == 0 { |
||||
id := _spec.ID.Value.(int64) |
||||
_node.ID = int64(id) |
||||
} |
||||
return _node, nil |
||||
} |
||||
|
||||
func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { |
||||
var ( |
||||
_node = &Comment{config: cc.config} |
||||
_spec = &sqlgraph.CreateSpec{ |
||||
Table: comment.Table, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
} |
||||
) |
||||
if id, ok := cc.mutation.ID(); ok { |
||||
_node.ID = id |
||||
_spec.ID.Value = id |
||||
} |
||||
if value, ok := cc.mutation.Name(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: comment.FieldName, |
||||
}) |
||||
_node.Name = value |
||||
} |
||||
if value, ok := cc.mutation.Content(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: comment.FieldContent, |
||||
}) |
||||
_node.Content = value |
||||
} |
||||
if value, ok := cc.mutation.CreatedAt(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: comment.FieldCreatedAt, |
||||
}) |
||||
_node.CreatedAt = value |
||||
} |
||||
if value, ok := cc.mutation.UpdatedAt(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: comment.FieldUpdatedAt, |
||||
}) |
||||
_node.UpdatedAt = value |
||||
} |
||||
if nodes := cc.mutation.PostIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2O, |
||||
Inverse: true, |
||||
Table: comment.PostTable, |
||||
Columns: []string{comment.PostColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges = append(_spec.Edges, edge) |
||||
} |
||||
return _node, _spec |
||||
} |
||||
|
||||
// CommentCreateBulk is the builder for creating many Comment entities in bulk.
|
||||
type CommentCreateBulk struct { |
||||
config |
||||
builders []*CommentCreate |
||||
} |
||||
|
||||
// Save creates the Comment entities in the database.
|
||||
func (ccb *CommentCreateBulk) Save(ctx context.Context) ([]*Comment, error) { |
||||
specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) |
||||
nodes := make([]*Comment, len(ccb.builders)) |
||||
mutators := make([]Mutator, len(ccb.builders)) |
||||
for i := range ccb.builders { |
||||
func(i int, root context.Context) { |
||||
builder := ccb.builders[i] |
||||
builder.defaults() |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*CommentMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
if err := builder.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
builder.mutation = mutation |
||||
nodes[i], specs[i] = builder.createSpec() |
||||
var err error |
||||
if i < len(mutators)-1 { |
||||
_, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation) |
||||
} else { |
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, ccb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil { |
||||
if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
} |
||||
} |
||||
mutation.done = true |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
if nodes[i].ID == 0 { |
||||
id := specs[i].ID.Value.(int64) |
||||
nodes[i].ID = int64(id) |
||||
} |
||||
return nodes[i], nil |
||||
}) |
||||
for i := len(builder.hooks) - 1; i >= 0; i-- { |
||||
mut = builder.hooks[i](mut) |
||||
} |
||||
mutators[i] = mut |
||||
}(i, ctx) |
||||
} |
||||
if len(mutators) > 0 { |
||||
if _, err := mutators[0].Mutate(ctx, ccb.builders[0].mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return nodes, nil |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ccb *CommentCreateBulk) SaveX(ctx context.Context) []*Comment { |
||||
v, err := ccb.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
@ -1,108 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
) |
||||
|
||||
// CommentDelete is the builder for deleting a Comment entity.
|
||||
type CommentDelete struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *CommentMutation |
||||
} |
||||
|
||||
// Where adds a new predicate to the CommentDelete builder.
|
||||
func (cd *CommentDelete) Where(ps ...predicate.Comment) *CommentDelete { |
||||
cd.mutation.predicates = append(cd.mutation.predicates, ps...) |
||||
return cd |
||||
} |
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (cd *CommentDelete) Exec(ctx context.Context) (int, error) { |
||||
var ( |
||||
err error |
||||
affected int |
||||
) |
||||
if len(cd.hooks) == 0 { |
||||
affected, err = cd.sqlExec(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*CommentMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
cd.mutation = mutation |
||||
affected, err = cd.sqlExec(ctx) |
||||
mutation.done = true |
||||
return affected, err |
||||
}) |
||||
for i := len(cd.hooks) - 1; i >= 0; i-- { |
||||
mut = cd.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, cd.mutation); err != nil { |
||||
return 0, err |
||||
} |
||||
} |
||||
return affected, err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cd *CommentDelete) ExecX(ctx context.Context) int { |
||||
n, err := cd.Exec(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return n |
||||
} |
||||
|
||||
func (cd *CommentDelete) sqlExec(ctx context.Context) (int, error) { |
||||
_spec := &sqlgraph.DeleteSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: comment.Table, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
if ps := cd.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
return sqlgraph.DeleteNodes(ctx, cd.driver, _spec) |
||||
} |
||||
|
||||
// CommentDeleteOne is the builder for deleting a single Comment entity.
|
||||
type CommentDeleteOne struct { |
||||
cd *CommentDelete |
||||
} |
||||
|
||||
// Exec executes the deletion query.
|
||||
func (cdo *CommentDeleteOne) Exec(ctx context.Context) error { |
||||
n, err := cdo.cd.Exec(ctx) |
||||
switch { |
||||
case err != nil: |
||||
return err |
||||
case n == 0: |
||||
return &NotFoundError{comment.Label} |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cdo *CommentDeleteOne) ExecX(ctx context.Context) { |
||||
cdo.cd.ExecX(ctx) |
||||
} |
@ -1,970 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"errors" |
||||
"fmt" |
||||
"math" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
) |
||||
|
||||
// CommentQuery is the builder for querying Comment entities.
|
||||
type CommentQuery struct { |
||||
config |
||||
limit *int |
||||
offset *int |
||||
order []OrderFunc |
||||
fields []string |
||||
predicates []predicate.Comment |
||||
// eager-loading edges.
|
||||
withPost *ArticleQuery |
||||
withFKs bool |
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector |
||||
path func(context.Context) (*sql.Selector, error) |
||||
} |
||||
|
||||
// Where adds a new predicate for the CommentQuery builder.
|
||||
func (cq *CommentQuery) Where(ps ...predicate.Comment) *CommentQuery { |
||||
cq.predicates = append(cq.predicates, ps...) |
||||
return cq |
||||
} |
||||
|
||||
// Limit adds a limit step to the query.
|
||||
func (cq *CommentQuery) Limit(limit int) *CommentQuery { |
||||
cq.limit = &limit |
||||
return cq |
||||
} |
||||
|
||||
// Offset adds an offset step to the query.
|
||||
func (cq *CommentQuery) Offset(offset int) *CommentQuery { |
||||
cq.offset = &offset |
||||
return cq |
||||
} |
||||
|
||||
// Order adds an order step to the query.
|
||||
func (cq *CommentQuery) Order(o ...OrderFunc) *CommentQuery { |
||||
cq.order = append(cq.order, o...) |
||||
return cq |
||||
} |
||||
|
||||
// QueryPost chains the current query on the "post" edge.
|
||||
func (cq *CommentQuery) QueryPost() *ArticleQuery { |
||||
query := &ArticleQuery{config: cq.config} |
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { |
||||
if err := cq.prepareQuery(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
selector := cq.sqlQuery(ctx) |
||||
if err := selector.Err(); err != nil { |
||||
return nil, err |
||||
} |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(comment.Table, comment.FieldID, selector), |
||||
sqlgraph.To(article.Table, article.FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2O, true, comment.PostTable, comment.PostColumn), |
||||
) |
||||
fromU = sqlgraph.SetNeighbors(cq.driver.Dialect(), step) |
||||
return fromU, nil |
||||
} |
||||
return query |
||||
} |
||||
|
||||
// First returns the first Comment entity from the query.
|
||||
// Returns a *NotFoundError when no Comment was found.
|
||||
func (cq *CommentQuery) First(ctx context.Context) (*Comment, error) { |
||||
nodes, err := cq.Limit(1).All(ctx) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
if len(nodes) == 0 { |
||||
return nil, &NotFoundError{comment.Label} |
||||
} |
||||
return nodes[0], nil |
||||
} |
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (cq *CommentQuery) FirstX(ctx context.Context) *Comment { |
||||
node, err := cq.First(ctx) |
||||
if err != nil && !IsNotFound(err) { |
||||
panic(err) |
||||
} |
||||
return node |
||||
} |
||||
|
||||
// FirstID returns the first Comment ID from the query.
|
||||
// Returns a *NotFoundError when no Comment ID was found.
|
||||
func (cq *CommentQuery) FirstID(ctx context.Context) (id int64, err error) { |
||||
var ids []int64 |
||||
if ids, err = cq.Limit(1).IDs(ctx); err != nil { |
||||
return |
||||
} |
||||
if len(ids) == 0 { |
||||
err = &NotFoundError{comment.Label} |
||||
return |
||||
} |
||||
return ids[0], nil |
||||
} |
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (cq *CommentQuery) FirstIDX(ctx context.Context) int64 { |
||||
id, err := cq.FirstID(ctx) |
||||
if err != nil && !IsNotFound(err) { |
||||
panic(err) |
||||
} |
||||
return id |
||||
} |
||||
|
||||
// Only returns a single Comment entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when exactly one Comment entity is not found.
|
||||
// Returns a *NotFoundError when no Comment entities are found.
|
||||
func (cq *CommentQuery) Only(ctx context.Context) (*Comment, error) { |
||||
nodes, err := cq.Limit(2).All(ctx) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
switch len(nodes) { |
||||
case 1: |
||||
return nodes[0], nil |
||||
case 0: |
||||
return nil, &NotFoundError{comment.Label} |
||||
default: |
||||
return nil, &NotSingularError{comment.Label} |
||||
} |
||||
} |
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (cq *CommentQuery) OnlyX(ctx context.Context) *Comment { |
||||
node, err := cq.Only(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return node |
||||
} |
||||
|
||||
// OnlyID is like Only, but returns the only Comment ID in the query.
|
||||
// Returns a *NotSingularError when exactly one Comment ID is not found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (cq *CommentQuery) OnlyID(ctx context.Context) (id int64, err error) { |
||||
var ids []int64 |
||||
if ids, err = cq.Limit(2).IDs(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(ids) { |
||||
case 1: |
||||
id = ids[0] |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = &NotSingularError{comment.Label} |
||||
} |
||||
return |
||||
} |
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (cq *CommentQuery) OnlyIDX(ctx context.Context) int64 { |
||||
id, err := cq.OnlyID(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return id |
||||
} |
||||
|
||||
// All executes the query and returns a list of Comments.
|
||||
func (cq *CommentQuery) All(ctx context.Context) ([]*Comment, error) { |
||||
if err := cq.prepareQuery(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
return cq.sqlAll(ctx) |
||||
} |
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (cq *CommentQuery) AllX(ctx context.Context) []*Comment { |
||||
nodes, err := cq.All(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return nodes |
||||
} |
||||
|
||||
// IDs executes the query and returns a list of Comment IDs.
|
||||
func (cq *CommentQuery) IDs(ctx context.Context) ([]int64, error) { |
||||
var ids []int64 |
||||
if err := cq.Select(comment.FieldID).Scan(ctx, &ids); err != nil { |
||||
return nil, err |
||||
} |
||||
return ids, nil |
||||
} |
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (cq *CommentQuery) IDsX(ctx context.Context) []int64 { |
||||
ids, err := cq.IDs(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return ids |
||||
} |
||||
|
||||
// Count returns the count of the given query.
|
||||
func (cq *CommentQuery) Count(ctx context.Context) (int, error) { |
||||
if err := cq.prepareQuery(ctx); err != nil { |
||||
return 0, err |
||||
} |
||||
return cq.sqlCount(ctx) |
||||
} |
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (cq *CommentQuery) CountX(ctx context.Context) int { |
||||
count, err := cq.Count(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return count |
||||
} |
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (cq *CommentQuery) Exist(ctx context.Context) (bool, error) { |
||||
if err := cq.prepareQuery(ctx); err != nil { |
||||
return false, err |
||||
} |
||||
return cq.sqlExist(ctx) |
||||
} |
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (cq *CommentQuery) ExistX(ctx context.Context) bool { |
||||
exist, err := cq.Exist(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return exist |
||||
} |
||||
|
||||
// Clone returns a duplicate of the CommentQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (cq *CommentQuery) Clone() *CommentQuery { |
||||
if cq == nil { |
||||
return nil |
||||
} |
||||
return &CommentQuery{ |
||||
config: cq.config, |
||||
limit: cq.limit, |
||||
offset: cq.offset, |
||||
order: append([]OrderFunc{}, cq.order...), |
||||
predicates: append([]predicate.Comment{}, cq.predicates...), |
||||
withPost: cq.withPost.Clone(), |
||||
// clone intermediate query.
|
||||
sql: cq.sql.Clone(), |
||||
path: cq.path, |
||||
} |
||||
} |
||||
|
||||
// WithPost tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "post" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (cq *CommentQuery) WithPost(opts ...func(*ArticleQuery)) *CommentQuery { |
||||
query := &ArticleQuery{config: cq.config} |
||||
for _, opt := range opts { |
||||
opt(query) |
||||
} |
||||
cq.withPost = query |
||||
return cq |
||||
} |
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Comment.Query().
|
||||
// GroupBy(comment.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (cq *CommentQuery) GroupBy(field string, fields ...string) *CommentGroupBy { |
||||
group := &CommentGroupBy{config: cq.config} |
||||
group.fields = append([]string{field}, fields...) |
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) { |
||||
if err := cq.prepareQuery(ctx); err != nil { |
||||
return nil, err |
||||
} |
||||
return cq.sqlQuery(ctx), nil |
||||
} |
||||
return group |
||||
} |
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Comment.Query().
|
||||
// Select(comment.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (cq *CommentQuery) Select(field string, fields ...string) *CommentSelect { |
||||
cq.fields = append([]string{field}, fields...) |
||||
return &CommentSelect{CommentQuery: cq} |
||||
} |
||||
|
||||
func (cq *CommentQuery) prepareQuery(ctx context.Context) error { |
||||
for _, f := range cq.fields { |
||||
if !comment.ValidColumn(f) { |
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} |
||||
} |
||||
} |
||||
if cq.path != nil { |
||||
prev, err := cq.path(ctx) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
cq.sql = prev |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (cq *CommentQuery) sqlAll(ctx context.Context) ([]*Comment, error) { |
||||
var ( |
||||
nodes = []*Comment{} |
||||
withFKs = cq.withFKs |
||||
_spec = cq.querySpec() |
||||
loadedTypes = [1]bool{ |
||||
cq.withPost != nil, |
||||
} |
||||
) |
||||
if cq.withPost != nil { |
||||
withFKs = true |
||||
} |
||||
if withFKs { |
||||
_spec.Node.Columns = append(_spec.Node.Columns, comment.ForeignKeys...) |
||||
} |
||||
_spec.ScanValues = func(columns []string) ([]interface{}, error) { |
||||
node := &Comment{config: cq.config} |
||||
nodes = append(nodes, node) |
||||
return node.scanValues(columns) |
||||
} |
||||
_spec.Assign = func(columns []string, values []interface{}) error { |
||||
if len(nodes) == 0 { |
||||
return fmt.Errorf("ent: Assign called without calling ScanValues") |
||||
} |
||||
node := nodes[len(nodes)-1] |
||||
node.Edges.loadedTypes = loadedTypes |
||||
return node.assignValues(columns, values) |
||||
} |
||||
if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil { |
||||
return nil, err |
||||
} |
||||
if len(nodes) == 0 { |
||||
return nodes, nil |
||||
} |
||||
|
||||
if query := cq.withPost; query != nil { |
||||
ids := make([]int64, 0, len(nodes)) |
||||
nodeids := make(map[int64][]*Comment) |
||||
for i := range nodes { |
||||
if fk := nodes[i].article_comments; fk != nil { |
||||
ids = append(ids, *fk) |
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i]) |
||||
} |
||||
} |
||||
query.Where(article.IDIn(ids...)) |
||||
neighbors, err := query.All(ctx) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
for _, n := range neighbors { |
||||
nodes, ok := nodeids[n.ID] |
||||
if !ok { |
||||
return nil, fmt.Errorf(`unexpected foreign-key "article_comments" returned %v`, n.ID) |
||||
} |
||||
for i := range nodes { |
||||
nodes[i].Edges.Post = n |
||||
} |
||||
} |
||||
} |
||||
|
||||
return nodes, nil |
||||
} |
||||
|
||||
func (cq *CommentQuery) sqlCount(ctx context.Context) (int, error) { |
||||
_spec := cq.querySpec() |
||||
return sqlgraph.CountNodes(ctx, cq.driver, _spec) |
||||
} |
||||
|
||||
func (cq *CommentQuery) sqlExist(ctx context.Context) (bool, error) { |
||||
n, err := cq.sqlCount(ctx) |
||||
if err != nil { |
||||
return false, fmt.Errorf("ent: check existence: %v", err) |
||||
} |
||||
return n > 0, nil |
||||
} |
||||
|
||||
func (cq *CommentQuery) querySpec() *sqlgraph.QuerySpec { |
||||
_spec := &sqlgraph.QuerySpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: comment.Table, |
||||
Columns: comment.Columns, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
From: cq.sql, |
||||
Unique: true, |
||||
} |
||||
if fields := cq.fields; len(fields) > 0 { |
||||
_spec.Node.Columns = make([]string, 0, len(fields)) |
||||
_spec.Node.Columns = append(_spec.Node.Columns, comment.FieldID) |
||||
for i := range fields { |
||||
if fields[i] != comment.FieldID { |
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i]) |
||||
} |
||||
} |
||||
} |
||||
if ps := cq.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
if limit := cq.limit; limit != nil { |
||||
_spec.Limit = *limit |
||||
} |
||||
if offset := cq.offset; offset != nil { |
||||
_spec.Offset = *offset |
||||
} |
||||
if ps := cq.order; len(ps) > 0 { |
||||
_spec.Order = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector, comment.ValidColumn) |
||||
} |
||||
} |
||||
} |
||||
return _spec |
||||
} |
||||
|
||||
func (cq *CommentQuery) sqlQuery(ctx context.Context) *sql.Selector { |
||||
builder := sql.Dialect(cq.driver.Dialect()) |
||||
t1 := builder.Table(comment.Table) |
||||
selector := builder.Select(t1.Columns(comment.Columns...)...).From(t1) |
||||
if cq.sql != nil { |
||||
selector = cq.sql |
||||
selector.Select(selector.Columns(comment.Columns...)...) |
||||
} |
||||
for _, p := range cq.predicates { |
||||
p(selector) |
||||
} |
||||
for _, p := range cq.order { |
||||
p(selector, comment.ValidColumn) |
||||
} |
||||
if offset := cq.offset; offset != nil { |
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32) |
||||
} |
||||
if limit := cq.limit; limit != nil { |
||||
selector.Limit(*limit) |
||||
} |
||||
return selector |
||||
} |
||||
|
||||
// CommentGroupBy is the group-by builder for Comment entities.
|
||||
type CommentGroupBy struct { |
||||
config |
||||
fields []string |
||||
fns []AggregateFunc |
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector |
||||
path func(context.Context) (*sql.Selector, error) |
||||
} |
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (cgb *CommentGroupBy) Aggregate(fns ...AggregateFunc) *CommentGroupBy { |
||||
cgb.fns = append(cgb.fns, fns...) |
||||
return cgb |
||||
} |
||||
|
||||
// Scan applies the group-by query and scans the result into the given value.
|
||||
func (cgb *CommentGroupBy) Scan(ctx context.Context, v interface{}) error { |
||||
query, err := cgb.path(ctx) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
cgb.sql = query |
||||
return cgb.sqlScan(ctx, v) |
||||
} |
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) ScanX(ctx context.Context, v interface{}) { |
||||
if err := cgb.Scan(ctx, v); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
||||
|
||||
// Strings returns list of strings from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (cgb *CommentGroupBy) Strings(ctx context.Context) ([]string, error) { |
||||
if len(cgb.fields) > 1 { |
||||
return nil, errors.New("ent: CommentGroupBy.Strings is not achievable when grouping more than 1 field") |
||||
} |
||||
var v []string |
||||
if err := cgb.Scan(ctx, &v); err != nil { |
||||
return nil, err |
||||
} |
||||
return v, nil |
||||
} |
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) StringsX(ctx context.Context) []string { |
||||
v, err := cgb.Strings(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// String returns a single string from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (cgb *CommentGroupBy) String(ctx context.Context) (_ string, err error) { |
||||
var v []string |
||||
if v, err = cgb.Strings(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(v) { |
||||
case 1: |
||||
return v[0], nil |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = fmt.Errorf("ent: CommentGroupBy.Strings returned %d results when one was expected", len(v)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) StringX(ctx context.Context) string { |
||||
v, err := cgb.String(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Ints returns list of ints from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (cgb *CommentGroupBy) Ints(ctx context.Context) ([]int, error) { |
||||
if len(cgb.fields) > 1 { |
||||
return nil, errors.New("ent: CommentGroupBy.Ints is not achievable when grouping more than 1 field") |
||||
} |
||||
var v []int |
||||
if err := cgb.Scan(ctx, &v); err != nil { |
||||
return nil, err |
||||
} |
||||
return v, nil |
||||
} |
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) IntsX(ctx context.Context) []int { |
||||
v, err := cgb.Ints(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Int returns a single int from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (cgb *CommentGroupBy) Int(ctx context.Context) (_ int, err error) { |
||||
var v []int |
||||
if v, err = cgb.Ints(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(v) { |
||||
case 1: |
||||
return v[0], nil |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = fmt.Errorf("ent: CommentGroupBy.Ints returned %d results when one was expected", len(v)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) IntX(ctx context.Context) int { |
||||
v, err := cgb.Int(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Float64s returns list of float64s from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (cgb *CommentGroupBy) Float64s(ctx context.Context) ([]float64, error) { |
||||
if len(cgb.fields) > 1 { |
||||
return nil, errors.New("ent: CommentGroupBy.Float64s is not achievable when grouping more than 1 field") |
||||
} |
||||
var v []float64 |
||||
if err := cgb.Scan(ctx, &v); err != nil { |
||||
return nil, err |
||||
} |
||||
return v, nil |
||||
} |
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) Float64sX(ctx context.Context) []float64 { |
||||
v, err := cgb.Float64s(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Float64 returns a single float64 from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (cgb *CommentGroupBy) Float64(ctx context.Context) (_ float64, err error) { |
||||
var v []float64 |
||||
if v, err = cgb.Float64s(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(v) { |
||||
case 1: |
||||
return v[0], nil |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = fmt.Errorf("ent: CommentGroupBy.Float64s returned %d results when one was expected", len(v)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) Float64X(ctx context.Context) float64 { |
||||
v, err := cgb.Float64(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Bools returns list of bools from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (cgb *CommentGroupBy) Bools(ctx context.Context) ([]bool, error) { |
||||
if len(cgb.fields) > 1 { |
||||
return nil, errors.New("ent: CommentGroupBy.Bools is not achievable when grouping more than 1 field") |
||||
} |
||||
var v []bool |
||||
if err := cgb.Scan(ctx, &v); err != nil { |
||||
return nil, err |
||||
} |
||||
return v, nil |
||||
} |
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) BoolsX(ctx context.Context) []bool { |
||||
v, err := cgb.Bools(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Bool returns a single bool from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (cgb *CommentGroupBy) Bool(ctx context.Context) (_ bool, err error) { |
||||
var v []bool |
||||
if v, err = cgb.Bools(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(v) { |
||||
case 1: |
||||
return v[0], nil |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = fmt.Errorf("ent: CommentGroupBy.Bools returned %d results when one was expected", len(v)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (cgb *CommentGroupBy) BoolX(ctx context.Context) bool { |
||||
v, err := cgb.Bool(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
func (cgb *CommentGroupBy) sqlScan(ctx context.Context, v interface{}) error { |
||||
for _, f := range cgb.fields { |
||||
if !comment.ValidColumn(f) { |
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} |
||||
} |
||||
} |
||||
selector := cgb.sqlQuery() |
||||
if err := selector.Err(); err != nil { |
||||
return err |
||||
} |
||||
rows := &sql.Rows{} |
||||
query, args := selector.Query() |
||||
if err := cgb.driver.Query(ctx, query, args, rows); err != nil { |
||||
return err |
||||
} |
||||
defer rows.Close() |
||||
return sql.ScanSlice(rows, v) |
||||
} |
||||
|
||||
func (cgb *CommentGroupBy) sqlQuery() *sql.Selector { |
||||
selector := cgb.sql |
||||
columns := make([]string, 0, len(cgb.fields)+len(cgb.fns)) |
||||
columns = append(columns, cgb.fields...) |
||||
for _, fn := range cgb.fns { |
||||
columns = append(columns, fn(selector, comment.ValidColumn)) |
||||
} |
||||
return selector.Select(columns...).GroupBy(cgb.fields...) |
||||
} |
||||
|
||||
// CommentSelect is the builder for selecting fields of Comment entities.
|
||||
type CommentSelect struct { |
||||
*CommentQuery |
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector |
||||
} |
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (cs *CommentSelect) Scan(ctx context.Context, v interface{}) error { |
||||
if err := cs.prepareQuery(ctx); err != nil { |
||||
return err |
||||
} |
||||
cs.sql = cs.CommentQuery.sqlQuery(ctx) |
||||
return cs.sqlScan(ctx, v) |
||||
} |
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (cs *CommentSelect) ScanX(ctx context.Context, v interface{}) { |
||||
if err := cs.Scan(ctx, v); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
||||
|
||||
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||
func (cs *CommentSelect) Strings(ctx context.Context) ([]string, error) { |
||||
if len(cs.fields) > 1 { |
||||
return nil, errors.New("ent: CommentSelect.Strings is not achievable when selecting more than 1 field") |
||||
} |
||||
var v []string |
||||
if err := cs.Scan(ctx, &v); err != nil { |
||||
return nil, err |
||||
} |
||||
return v, nil |
||||
} |
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (cs *CommentSelect) StringsX(ctx context.Context) []string { |
||||
v, err := cs.Strings(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||
func (cs *CommentSelect) String(ctx context.Context) (_ string, err error) { |
||||
var v []string |
||||
if v, err = cs.Strings(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(v) { |
||||
case 1: |
||||
return v[0], nil |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = fmt.Errorf("ent: CommentSelect.Strings returned %d results when one was expected", len(v)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (cs *CommentSelect) StringX(ctx context.Context) string { |
||||
v, err := cs.String(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||
func (cs *CommentSelect) Ints(ctx context.Context) ([]int, error) { |
||||
if len(cs.fields) > 1 { |
||||
return nil, errors.New("ent: CommentSelect.Ints is not achievable when selecting more than 1 field") |
||||
} |
||||
var v []int |
||||
if err := cs.Scan(ctx, &v); err != nil { |
||||
return nil, err |
||||
} |
||||
return v, nil |
||||
} |
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (cs *CommentSelect) IntsX(ctx context.Context) []int { |
||||
v, err := cs.Ints(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||
func (cs *CommentSelect) Int(ctx context.Context) (_ int, err error) { |
||||
var v []int |
||||
if v, err = cs.Ints(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(v) { |
||||
case 1: |
||||
return v[0], nil |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = fmt.Errorf("ent: CommentSelect.Ints returned %d results when one was expected", len(v)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (cs *CommentSelect) IntX(ctx context.Context) int { |
||||
v, err := cs.Int(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||
func (cs *CommentSelect) Float64s(ctx context.Context) ([]float64, error) { |
||||
if len(cs.fields) > 1 { |
||||
return nil, errors.New("ent: CommentSelect.Float64s is not achievable when selecting more than 1 field") |
||||
} |
||||
var v []float64 |
||||
if err := cs.Scan(ctx, &v); err != nil { |
||||
return nil, err |
||||
} |
||||
return v, nil |
||||
} |
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (cs *CommentSelect) Float64sX(ctx context.Context) []float64 { |
||||
v, err := cs.Float64s(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||
func (cs *CommentSelect) Float64(ctx context.Context) (_ float64, err error) { |
||||
var v []float64 |
||||
if v, err = cs.Float64s(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(v) { |
||||
case 1: |
||||
return v[0], nil |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = fmt.Errorf("ent: CommentSelect.Float64s returned %d results when one was expected", len(v)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (cs *CommentSelect) Float64X(ctx context.Context) float64 { |
||||
v, err := cs.Float64(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||
func (cs *CommentSelect) Bools(ctx context.Context) ([]bool, error) { |
||||
if len(cs.fields) > 1 { |
||||
return nil, errors.New("ent: CommentSelect.Bools is not achievable when selecting more than 1 field") |
||||
} |
||||
var v []bool |
||||
if err := cs.Scan(ctx, &v); err != nil { |
||||
return nil, err |
||||
} |
||||
return v, nil |
||||
} |
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (cs *CommentSelect) BoolsX(ctx context.Context) []bool { |
||||
v, err := cs.Bools(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||
func (cs *CommentSelect) Bool(ctx context.Context) (_ bool, err error) { |
||||
var v []bool |
||||
if v, err = cs.Bools(ctx); err != nil { |
||||
return |
||||
} |
||||
switch len(v) { |
||||
case 1: |
||||
return v[0], nil |
||||
case 0: |
||||
err = &NotFoundError{comment.Label} |
||||
default: |
||||
err = fmt.Errorf("ent: CommentSelect.Bools returned %d results when one was expected", len(v)) |
||||
} |
||||
return |
||||
} |
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (cs *CommentSelect) BoolX(ctx context.Context) bool { |
||||
v, err := cs.Bool(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
func (cs *CommentSelect) sqlScan(ctx context.Context, v interface{}) error { |
||||
rows := &sql.Rows{} |
||||
query, args := cs.sqlQuery().Query() |
||||
if err := cs.driver.Query(ctx, query, args, rows); err != nil { |
||||
return err |
||||
} |
||||
defer rows.Close() |
||||
return sql.ScanSlice(rows, v) |
||||
} |
||||
|
||||
func (cs *CommentSelect) sqlQuery() sql.Querier { |
||||
selector := cs.sql |
||||
selector.Select(selector.Columns(cs.fields...)...) |
||||
return selector |
||||
} |
@ -1,470 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
) |
||||
|
||||
// CommentUpdate is the builder for updating Comment entities.
|
||||
type CommentUpdate struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *CommentMutation |
||||
} |
||||
|
||||
// Where adds a new predicate for the CommentUpdate builder.
|
||||
func (cu *CommentUpdate) Where(ps ...predicate.Comment) *CommentUpdate { |
||||
cu.mutation.predicates = append(cu.mutation.predicates, ps...) |
||||
return cu |
||||
} |
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cu *CommentUpdate) SetName(s string) *CommentUpdate { |
||||
cu.mutation.SetName(s) |
||||
return cu |
||||
} |
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (cu *CommentUpdate) SetContent(s string) *CommentUpdate { |
||||
cu.mutation.SetContent(s) |
||||
return cu |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (cu *CommentUpdate) SetCreatedAt(t time.Time) *CommentUpdate { |
||||
cu.mutation.SetCreatedAt(t) |
||||
return cu |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (cu *CommentUpdate) SetNillableCreatedAt(t *time.Time) *CommentUpdate { |
||||
if t != nil { |
||||
cu.SetCreatedAt(*t) |
||||
} |
||||
return cu |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (cu *CommentUpdate) SetUpdatedAt(t time.Time) *CommentUpdate { |
||||
cu.mutation.SetUpdatedAt(t) |
||||
return cu |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (cu *CommentUpdate) SetNillableUpdatedAt(t *time.Time) *CommentUpdate { |
||||
if t != nil { |
||||
cu.SetUpdatedAt(*t) |
||||
} |
||||
return cu |
||||
} |
||||
|
||||
// SetPostID sets the "post" edge to the Article entity by ID.
|
||||
func (cu *CommentUpdate) SetPostID(id int64) *CommentUpdate { |
||||
cu.mutation.SetPostID(id) |
||||
return cu |
||||
} |
||||
|
||||
// SetNillablePostID sets the "post" edge to the Article entity by ID if the given value is not nil.
|
||||
func (cu *CommentUpdate) SetNillablePostID(id *int64) *CommentUpdate { |
||||
if id != nil { |
||||
cu = cu.SetPostID(*id) |
||||
} |
||||
return cu |
||||
} |
||||
|
||||
// SetPost sets the "post" edge to the Article entity.
|
||||
func (cu *CommentUpdate) SetPost(a *Article) *CommentUpdate { |
||||
return cu.SetPostID(a.ID) |
||||
} |
||||
|
||||
// Mutation returns the CommentMutation object of the builder.
|
||||
func (cu *CommentUpdate) Mutation() *CommentMutation { |
||||
return cu.mutation |
||||
} |
||||
|
||||
// ClearPost clears the "post" edge to the Article entity.
|
||||
func (cu *CommentUpdate) ClearPost() *CommentUpdate { |
||||
cu.mutation.ClearPost() |
||||
return cu |
||||
} |
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (cu *CommentUpdate) Save(ctx context.Context) (int, error) { |
||||
var ( |
||||
err error |
||||
affected int |
||||
) |
||||
if len(cu.hooks) == 0 { |
||||
affected, err = cu.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*CommentMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
cu.mutation = mutation |
||||
affected, err = cu.sqlSave(ctx) |
||||
mutation.done = true |
||||
return affected, err |
||||
}) |
||||
for i := len(cu.hooks) - 1; i >= 0; i-- { |
||||
mut = cu.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, cu.mutation); err != nil { |
||||
return 0, err |
||||
} |
||||
} |
||||
return affected, err |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cu *CommentUpdate) SaveX(ctx context.Context) int { |
||||
affected, err := cu.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return affected |
||||
} |
||||
|
||||
// Exec executes the query.
|
||||
func (cu *CommentUpdate) Exec(ctx context.Context) error { |
||||
_, err := cu.Save(ctx) |
||||
return err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cu *CommentUpdate) ExecX(ctx context.Context) { |
||||
if err := cu.Exec(ctx); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
||||
|
||||
func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { |
||||
_spec := &sqlgraph.UpdateSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: comment.Table, |
||||
Columns: comment.Columns, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
if ps := cu.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
if value, ok := cu.mutation.Name(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: comment.FieldName, |
||||
}) |
||||
} |
||||
if value, ok := cu.mutation.Content(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: comment.FieldContent, |
||||
}) |
||||
} |
||||
if value, ok := cu.mutation.CreatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: comment.FieldCreatedAt, |
||||
}) |
||||
} |
||||
if value, ok := cu.mutation.UpdatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: comment.FieldUpdatedAt, |
||||
}) |
||||
} |
||||
if cu.mutation.PostCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2O, |
||||
Inverse: true, |
||||
Table: comment.PostTable, |
||||
Columns: []string{comment.PostColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := cu.mutation.PostIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2O, |
||||
Inverse: true, |
||||
Table: comment.PostTable, |
||||
Columns: []string{comment.PostColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge) |
||||
} |
||||
if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil { |
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
||||
err = &NotFoundError{comment.Label} |
||||
} else if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return 0, err |
||||
} |
||||
return n, nil |
||||
} |
||||
|
||||
// CommentUpdateOne is the builder for updating a single Comment entity.
|
||||
type CommentUpdateOne struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *CommentMutation |
||||
} |
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cuo *CommentUpdateOne) SetName(s string) *CommentUpdateOne { |
||||
cuo.mutation.SetName(s) |
||||
return cuo |
||||
} |
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (cuo *CommentUpdateOne) SetContent(s string) *CommentUpdateOne { |
||||
cuo.mutation.SetContent(s) |
||||
return cuo |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (cuo *CommentUpdateOne) SetCreatedAt(t time.Time) *CommentUpdateOne { |
||||
cuo.mutation.SetCreatedAt(t) |
||||
return cuo |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (cuo *CommentUpdateOne) SetNillableCreatedAt(t *time.Time) *CommentUpdateOne { |
||||
if t != nil { |
||||
cuo.SetCreatedAt(*t) |
||||
} |
||||
return cuo |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (cuo *CommentUpdateOne) SetUpdatedAt(t time.Time) *CommentUpdateOne { |
||||
cuo.mutation.SetUpdatedAt(t) |
||||
return cuo |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (cuo *CommentUpdateOne) SetNillableUpdatedAt(t *time.Time) *CommentUpdateOne { |
||||
if t != nil { |
||||
cuo.SetUpdatedAt(*t) |
||||
} |
||||
return cuo |
||||
} |
||||
|
||||
// SetPostID sets the "post" edge to the Article entity by ID.
|
||||
func (cuo *CommentUpdateOne) SetPostID(id int64) *CommentUpdateOne { |
||||
cuo.mutation.SetPostID(id) |
||||
return cuo |
||||
} |
||||
|
||||
// SetNillablePostID sets the "post" edge to the Article entity by ID if the given value is not nil.
|
||||
func (cuo *CommentUpdateOne) SetNillablePostID(id *int64) *CommentUpdateOne { |
||||
if id != nil { |
||||
cuo = cuo.SetPostID(*id) |
||||
} |
||||
return cuo |
||||
} |
||||
|
||||
// SetPost sets the "post" edge to the Article entity.
|
||||
func (cuo *CommentUpdateOne) SetPost(a *Article) *CommentUpdateOne { |
||||
return cuo.SetPostID(a.ID) |
||||
} |
||||
|
||||
// Mutation returns the CommentMutation object of the builder.
|
||||
func (cuo *CommentUpdateOne) Mutation() *CommentMutation { |
||||
return cuo.mutation |
||||
} |
||||
|
||||
// ClearPost clears the "post" edge to the Article entity.
|
||||
func (cuo *CommentUpdateOne) ClearPost() *CommentUpdateOne { |
||||
cuo.mutation.ClearPost() |
||||
return cuo |
||||
} |
||||
|
||||
// Save executes the query and returns the updated Comment entity.
|
||||
func (cuo *CommentUpdateOne) Save(ctx context.Context) (*Comment, error) { |
||||
var ( |
||||
err error |
||||
node *Comment |
||||
) |
||||
if len(cuo.hooks) == 0 { |
||||
node, err = cuo.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*CommentMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
cuo.mutation = mutation |
||||
node, err = cuo.sqlSave(ctx) |
||||
mutation.done = true |
||||
return node, err |
||||
}) |
||||
for i := len(cuo.hooks) - 1; i >= 0; i-- { |
||||
mut = cuo.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, cuo.mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return node, err |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cuo *CommentUpdateOne) SaveX(ctx context.Context) *Comment { |
||||
node, err := cuo.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return node |
||||
} |
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (cuo *CommentUpdateOne) Exec(ctx context.Context) error { |
||||
_, err := cuo.Save(ctx) |
||||
return err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cuo *CommentUpdateOne) ExecX(ctx context.Context) { |
||||
if err := cuo.Exec(ctx); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
||||
|
||||
func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err error) { |
||||
_spec := &sqlgraph.UpdateSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: comment.Table, |
||||
Columns: comment.Columns, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: comment.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
id, ok := cuo.mutation.ID() |
||||
if !ok { |
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Comment.ID for update")} |
||||
} |
||||
_spec.Node.ID.Value = id |
||||
if ps := cuo.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
if value, ok := cuo.mutation.Name(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: comment.FieldName, |
||||
}) |
||||
} |
||||
if value, ok := cuo.mutation.Content(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: comment.FieldContent, |
||||
}) |
||||
} |
||||
if value, ok := cuo.mutation.CreatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: comment.FieldCreatedAt, |
||||
}) |
||||
} |
||||
if value, ok := cuo.mutation.UpdatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: comment.FieldUpdatedAt, |
||||
}) |
||||
} |
||||
if cuo.mutation.PostCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2O, |
||||
Inverse: true, |
||||
Table: comment.PostTable, |
||||
Columns: []string{comment.PostColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := cuo.mutation.PostIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2O, |
||||
Inverse: true, |
||||
Table: comment.PostTable, |
||||
Columns: []string{comment.PostColumn}, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge) |
||||
} |
||||
_node = &Comment{config: cuo.config} |
||||
_spec.Assign = _node.assignValues |
||||
_spec.ScanValues = _node.scanValues |
||||
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil { |
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
||||
err = &NotFoundError{comment.Label} |
||||
} else if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return nil, err |
||||
} |
||||
return _node, nil |
||||
} |
@ -1,61 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"entgo.io/ent" |
||||
"entgo.io/ent/dialect" |
||||
) |
||||
|
||||
// Option function to configure the client.
|
||||
type Option func(*config) |
||||
|
||||
// Config is the configuration for the client and its builder.
|
||||
type config struct { |
||||
// driver used for executing database requests.
|
||||
driver dialect.Driver |
||||
// debug enable a debug logging.
|
||||
debug bool |
||||
// log used for logging on debug mode.
|
||||
log func(...interface{}) |
||||
// hooks to execute on mutations.
|
||||
hooks *hooks |
||||
} |
||||
|
||||
// hooks per client, for fast access.
|
||||
type hooks struct { |
||||
Article []ent.Hook |
||||
Comment []ent.Hook |
||||
Tag []ent.Hook |
||||
} |
||||
|
||||
// Options applies the options on the config object.
|
||||
func (c *config) options(opts ...Option) { |
||||
for _, opt := range opts { |
||||
opt(c) |
||||
} |
||||
if c.debug { |
||||
c.driver = dialect.Debug(c.driver, c.log) |
||||
} |
||||
} |
||||
|
||||
// Debug enables debug logging on the ent.Driver.
|
||||
func Debug() Option { |
||||
return func(c *config) { |
||||
c.debug = true |
||||
} |
||||
} |
||||
|
||||
// Log sets the logging function for debug mode.
|
||||
func Log(fn func(...interface{})) Option { |
||||
return func(c *config) { |
||||
c.log = fn |
||||
} |
||||
} |
||||
|
||||
// Driver configures the client driver.
|
||||
func Driver(driver dialect.Driver) Option { |
||||
return func(c *config) { |
||||
c.driver = driver |
||||
} |
||||
} |
@ -1,33 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
) |
||||
|
||||
type clientCtxKey struct{} |
||||
|
||||
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||
func FromContext(ctx context.Context) *Client { |
||||
c, _ := ctx.Value(clientCtxKey{}).(*Client) |
||||
return c |
||||
} |
||||
|
||||
// NewContext returns a new context with the given Client attached.
|
||||
func NewContext(parent context.Context, c *Client) context.Context { |
||||
return context.WithValue(parent, clientCtxKey{}, c) |
||||
} |
||||
|
||||
type txCtxKey struct{} |
||||
|
||||
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||
func TxFromContext(ctx context.Context) *Tx { |
||||
tx, _ := ctx.Value(txCtxKey{}).(*Tx) |
||||
return tx |
||||
} |
||||
|
||||
// NewTxContext returns a new context with the given Tx attached.
|
||||
func NewTxContext(parent context.Context, tx *Tx) context.Context { |
||||
return context.WithValue(parent, txCtxKey{}, tx) |
||||
} |
@ -1,270 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"errors" |
||||
"fmt" |
||||
"strings" |
||||
|
||||
"entgo.io/ent" |
||||
"entgo.io/ent/dialect" |
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
) |
||||
|
||||
// ent aliases to avoid import conflicts in user's code.
|
||||
type ( |
||||
Op = ent.Op |
||||
Hook = ent.Hook |
||||
Value = ent.Value |
||||
Query = ent.Query |
||||
Policy = ent.Policy |
||||
Mutator = ent.Mutator |
||||
Mutation = ent.Mutation |
||||
MutateFunc = ent.MutateFunc |
||||
) |
||||
|
||||
// OrderFunc applies an ordering on the sql selector.
|
||||
type OrderFunc func(*sql.Selector, func(string) bool) |
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) OrderFunc { |
||||
return func(s *sql.Selector, check func(string) bool) { |
||||
for _, f := range fields { |
||||
if check(f) { |
||||
s.OrderBy(sql.Asc(f)) |
||||
} else { |
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("invalid field %q for ordering", f)}) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) OrderFunc { |
||||
return func(s *sql.Selector, check func(string) bool) { |
||||
for _, f := range fields { |
||||
if check(f) { |
||||
s.OrderBy(sql.Desc(f)) |
||||
} else { |
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("invalid field %q for ordering", f)}) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||
type AggregateFunc func(*sql.Selector, func(string) bool) string |
||||
|
||||
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||
//
|
||||
// GroupBy(field1, field2).
|
||||
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func As(fn AggregateFunc, end string) AggregateFunc { |
||||
return func(s *sql.Selector, check func(string) bool) string { |
||||
return sql.As(fn(s, check), end) |
||||
} |
||||
} |
||||
|
||||
// Count applies the "count" aggregation function on each group.
|
||||
func Count() AggregateFunc { |
||||
return func(s *sql.Selector, _ func(string) bool) string { |
||||
return sql.Count("*") |
||||
} |
||||
} |
||||
|
||||
// Max applies the "max" aggregation function on the given field of each group.
|
||||
func Max(field string) AggregateFunc { |
||||
return func(s *sql.Selector, check func(string) bool) string { |
||||
if !check(field) { |
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)}) |
||||
return "" |
||||
} |
||||
return sql.Max(s.C(field)) |
||||
} |
||||
} |
||||
|
||||
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||
func Mean(field string) AggregateFunc { |
||||
return func(s *sql.Selector, check func(string) bool) string { |
||||
if !check(field) { |
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)}) |
||||
return "" |
||||
} |
||||
return sql.Avg(s.C(field)) |
||||
} |
||||
} |
||||
|
||||
// Min applies the "min" aggregation function on the given field of each group.
|
||||
func Min(field string) AggregateFunc { |
||||
return func(s *sql.Selector, check func(string) bool) string { |
||||
if !check(field) { |
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)}) |
||||
return "" |
||||
} |
||||
return sql.Min(s.C(field)) |
||||
} |
||||
} |
||||
|
||||
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||
func Sum(field string) AggregateFunc { |
||||
return func(s *sql.Selector, check func(string) bool) string { |
||||
if !check(field) { |
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("invalid field %q for grouping", field)}) |
||||
return "" |
||||
} |
||||
return sql.Sum(s.C(field)) |
||||
} |
||||
} |
||||
|
||||
// ValidationError returns when validating a field fails.
|
||||
type ValidationError struct { |
||||
Name string // Field or edge name.
|
||||
err error |
||||
} |
||||
|
||||
// Error implements the error interface.
|
||||
func (e *ValidationError) Error() string { |
||||
return e.err.Error() |
||||
} |
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ValidationError) Unwrap() error { |
||||
return e.err |
||||
} |
||||
|
||||
// IsValidationError returns a boolean indicating whether the error is a validaton error.
|
||||
func IsValidationError(err error) bool { |
||||
if err == nil { |
||||
return false |
||||
} |
||||
var e *ValidationError |
||||
return errors.As(err, &e) |
||||
} |
||||
|
||||
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||
type NotFoundError struct { |
||||
label string |
||||
} |
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotFoundError) Error() string { |
||||
return "ent: " + e.label + " not found" |
||||
} |
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool { |
||||
if err == nil { |
||||
return false |
||||
} |
||||
var e *NotFoundError |
||||
return errors.As(err, &e) |
||||
} |
||||
|
||||
// MaskNotFound masks not found error.
|
||||
func MaskNotFound(err error) error { |
||||
if IsNotFound(err) { |
||||
return nil |
||||
} |
||||
return err |
||||
} |
||||
|
||||
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||
type NotSingularError struct { |
||||
label string |
||||
} |
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotSingularError) Error() string { |
||||
return "ent: " + e.label + " not singular" |
||||
} |
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool { |
||||
if err == nil { |
||||
return false |
||||
} |
||||
var e *NotSingularError |
||||
return errors.As(err, &e) |
||||
} |
||||
|
||||
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||
type NotLoadedError struct { |
||||
edge string |
||||
} |
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotLoadedError) Error() string { |
||||
return "ent: " + e.edge + " edge was not loaded" |
||||
} |
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool { |
||||
if err == nil { |
||||
return false |
||||
} |
||||
var e *NotLoadedError |
||||
return errors.As(err, &e) |
||||
} |
||||
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct { |
||||
msg string |
||||
wrap error |
||||
} |
||||
|
||||
// Error implements the error interface.
|
||||
func (e ConstraintError) Error() string { |
||||
return "ent: constraint failed: " + e.msg |
||||
} |
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ConstraintError) Unwrap() error { |
||||
return e.wrap |
||||
} |
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool { |
||||
if err == nil { |
||||
return false |
||||
} |
||||
var e *ConstraintError |
||||
return errors.As(err, &e) |
||||
} |
||||
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) { |
||||
var ( |
||||
msg = err.Error() |
||||
// error format per dialect.
|
||||
errors = [...]string{ |
||||
"Error 1062", // MySQL 1062 error (ER_DUP_ENTRY).
|
||||
"UNIQUE constraint failed", // SQLite.
|
||||
"duplicate key value violates unique constraint", // PostgreSQL.
|
||||
} |
||||
) |
||||
if _, ok := err.(*sqlgraph.ConstraintError); ok { |
||||
return &ConstraintError{msg, err}, true |
||||
} |
||||
for i := range errors { |
||||
if strings.Contains(msg, errors[i]) { |
||||
return &ConstraintError{msg, err}, true |
||||
} |
||||
} |
||||
return nil, false |
||||
} |
||||
|
||||
// rollback calls tx.Rollback and wraps the given error with the rollback error if present.
|
||||
func rollback(tx dialect.Tx, err error) error { |
||||
if rerr := tx.Rollback(); rerr != nil { |
||||
err = fmt.Errorf("%s: %v", err.Error(), rerr) |
||||
} |
||||
if err, ok := isSQLConstraintError(err); ok { |
||||
return err |
||||
} |
||||
return err |
||||
} |
@ -1,78 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package enttest |
||||
|
||||
import ( |
||||
"context" |
||||
|
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent" |
||||
// required by schema hooks.
|
||||
_ "github.com/go-kratos/kratos/examples/blog/internal/data/ent/runtime" |
||||
|
||||
"entgo.io/ent/dialect/sql/schema" |
||||
) |
||||
|
||||
type ( |
||||
// TestingT is the interface that is shared between
|
||||
// testing.T and testing.B and used by enttest.
|
||||
TestingT interface { |
||||
FailNow() |
||||
Error(...interface{}) |
||||
} |
||||
|
||||
// Option configures client creation.
|
||||
Option func(*options) |
||||
|
||||
options struct { |
||||
opts []ent.Option |
||||
migrateOpts []schema.MigrateOption |
||||
} |
||||
) |
||||
|
||||
// WithOptions forwards options to client creation.
|
||||
func WithOptions(opts ...ent.Option) Option { |
||||
return func(o *options) { |
||||
o.opts = append(o.opts, opts...) |
||||
} |
||||
} |
||||
|
||||
// WithMigrateOptions forwards options to auto migration.
|
||||
func WithMigrateOptions(opts ...schema.MigrateOption) Option { |
||||
return func(o *options) { |
||||
o.migrateOpts = append(o.migrateOpts, opts...) |
||||
} |
||||
} |
||||
|
||||
func newOptions(opts []Option) *options { |
||||
o := &options{} |
||||
for _, opt := range opts { |
||||
opt(o) |
||||
} |
||||
return o |
||||
} |
||||
|
||||
// Open calls ent.Open and auto-run migration.
|
||||
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { |
||||
o := newOptions(opts) |
||||
c, err := ent.Open(driverName, dataSourceName, o.opts...) |
||||
if err != nil { |
||||
t.Error(err) |
||||
t.FailNow() |
||||
} |
||||
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { |
||||
t.Error(err) |
||||
t.FailNow() |
||||
} |
||||
return c |
||||
} |
||||
|
||||
// NewClient calls ent.NewClient and auto-run migration.
|
||||
func NewClient(t TestingT, opts ...Option) *ent.Client { |
||||
o := newOptions(opts) |
||||
c := ent.NewClient(o.opts...) |
||||
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { |
||||
t.Error(err) |
||||
t.FailNow() |
||||
} |
||||
return c |
||||
} |
@ -1,230 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package hook |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
|
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent" |
||||
) |
||||
|
||||
// The ArticleFunc type is an adapter to allow the use of ordinary
|
||||
// function as Article mutator.
|
||||
type ArticleFunc func(context.Context, *ent.ArticleMutation) (ent.Value, error) |
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f ArticleFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { |
||||
mv, ok := m.(*ent.ArticleMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ArticleMutation", m) |
||||
} |
||||
return f(ctx, mv) |
||||
} |
||||
|
||||
// The CommentFunc type is an adapter to allow the use of ordinary
|
||||
// function as Comment mutator.
|
||||
type CommentFunc func(context.Context, *ent.CommentMutation) (ent.Value, error) |
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CommentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { |
||||
mv, ok := m.(*ent.CommentMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CommentMutation", m) |
||||
} |
||||
return f(ctx, mv) |
||||
} |
||||
|
||||
// The TagFunc type is an adapter to allow the use of ordinary
|
||||
// function as Tag mutator.
|
||||
type TagFunc func(context.Context, *ent.TagMutation) (ent.Value, error) |
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f TagFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { |
||||
mv, ok := m.(*ent.TagMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TagMutation", m) |
||||
} |
||||
return f(ctx, mv) |
||||
} |
||||
|
||||
// Condition is a hook condition function.
|
||||
type Condition func(context.Context, ent.Mutation) bool |
||||
|
||||
// And groups conditions with the AND operator.
|
||||
func And(first, second Condition, rest ...Condition) Condition { |
||||
return func(ctx context.Context, m ent.Mutation) bool { |
||||
if !first(ctx, m) || !second(ctx, m) { |
||||
return false |
||||
} |
||||
for _, cond := range rest { |
||||
if !cond(ctx, m) { |
||||
return false |
||||
} |
||||
} |
||||
return true |
||||
} |
||||
} |
||||
|
||||
// Or groups conditions with the OR operator.
|
||||
func Or(first, second Condition, rest ...Condition) Condition { |
||||
return func(ctx context.Context, m ent.Mutation) bool { |
||||
if first(ctx, m) || second(ctx, m) { |
||||
return true |
||||
} |
||||
for _, cond := range rest { |
||||
if cond(ctx, m) { |
||||
return true |
||||
} |
||||
} |
||||
return false |
||||
} |
||||
} |
||||
|
||||
// Not negates a given condition.
|
||||
func Not(cond Condition) Condition { |
||||
return func(ctx context.Context, m ent.Mutation) bool { |
||||
return !cond(ctx, m) |
||||
} |
||||
} |
||||
|
||||
// HasOp is a condition testing mutation operation.
|
||||
func HasOp(op ent.Op) Condition { |
||||
return func(_ context.Context, m ent.Mutation) bool { |
||||
return m.Op().Is(op) |
||||
} |
||||
} |
||||
|
||||
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||
func HasAddedFields(field string, fields ...string) Condition { |
||||
return func(_ context.Context, m ent.Mutation) bool { |
||||
if _, exists := m.AddedField(field); !exists { |
||||
return false |
||||
} |
||||
for _, field := range fields { |
||||
if _, exists := m.AddedField(field); !exists { |
||||
return false |
||||
} |
||||
} |
||||
return true |
||||
} |
||||
} |
||||
|
||||
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||
func HasClearedFields(field string, fields ...string) Condition { |
||||
return func(_ context.Context, m ent.Mutation) bool { |
||||
if exists := m.FieldCleared(field); !exists { |
||||
return false |
||||
} |
||||
for _, field := range fields { |
||||
if exists := m.FieldCleared(field); !exists { |
||||
return false |
||||
} |
||||
} |
||||
return true |
||||
} |
||||
} |
||||
|
||||
// HasFields is a condition validating `.Field` on fields.
|
||||
func HasFields(field string, fields ...string) Condition { |
||||
return func(_ context.Context, m ent.Mutation) bool { |
||||
if _, exists := m.Field(field); !exists { |
||||
return false |
||||
} |
||||
for _, field := range fields { |
||||
if _, exists := m.Field(field); !exists { |
||||
return false |
||||
} |
||||
} |
||||
return true |
||||
} |
||||
} |
||||
|
||||
// If executes the given hook under condition.
|
||||
//
|
||||
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||
//
|
||||
func If(hk ent.Hook, cond Condition) ent.Hook { |
||||
return func(next ent.Mutator) ent.Mutator { |
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { |
||||
if cond(ctx, m) { |
||||
return hk(next).Mutate(ctx, m) |
||||
} |
||||
return next.Mutate(ctx, m) |
||||
}) |
||||
} |
||||
} |
||||
|
||||
// On executes the given hook only for the given operation.
|
||||
//
|
||||
// hook.On(Log, ent.Delete|ent.Create)
|
||||
//
|
||||
func On(hk ent.Hook, op ent.Op) ent.Hook { |
||||
return If(hk, HasOp(op)) |
||||
} |
||||
|
||||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||
//
|
||||
func Unless(hk ent.Hook, op ent.Op) ent.Hook { |
||||
return If(hk, Not(HasOp(op))) |
||||
} |
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook { |
||||
return func(ent.Mutator) ent.Mutator { |
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { |
||||
return nil, err |
||||
}) |
||||
} |
||||
} |
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
// return []ent.Hook{
|
||||
// Reject(ent.Delete|ent.Update),
|
||||
// }
|
||||
// }
|
||||
//
|
||||
func Reject(op ent.Op) ent.Hook { |
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) |
||||
return On(hk, op) |
||||
} |
||||
|
||||
// Chain acts as a list of hooks and is effectively immutable.
|
||||
// Once created, it will always hold the same set of hooks in the same order.
|
||||
type Chain struct { |
||||
hooks []ent.Hook |
||||
} |
||||
|
||||
// NewChain creates a new chain of hooks.
|
||||
func NewChain(hooks ...ent.Hook) Chain { |
||||
return Chain{append([]ent.Hook(nil), hooks...)} |
||||
} |
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() ent.Hook { |
||||
return func(mutator ent.Mutator) ent.Mutator { |
||||
for i := len(c.hooks) - 1; i >= 0; i-- { |
||||
mutator = c.hooks[i](mutator) |
||||
} |
||||
return mutator |
||||
} |
||||
} |
||||
|
||||
// Append extends a chain, adding the specified hook
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Append(hooks ...ent.Hook) Chain { |
||||
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) |
||||
newHooks = append(newHooks, c.hooks...) |
||||
newHooks = append(newHooks, hooks...) |
||||
return Chain{newHooks} |
||||
} |
||||
|
||||
// Extend extends a chain, adding the specified chain
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Extend(chain Chain) Chain { |
||||
return c.Append(chain.hooks...) |
||||
} |
@ -1,72 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package migrate |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"io" |
||||
|
||||
"entgo.io/ent/dialect" |
||||
"entgo.io/ent/dialect/sql/schema" |
||||
) |
||||
|
||||
var ( |
||||
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||
// for the ids of each entity (table).
|
||||
// Note that this option cannot be applied on tables that already exist.
|
||||
WithGlobalUniqueID = schema.WithGlobalUniqueID |
||||
// WithDropColumn sets the drop column option to the migration.
|
||||
// If this option is enabled, ent migration will drop old columns
|
||||
// that were used for both fields and edges. This defaults to false.
|
||||
WithDropColumn = schema.WithDropColumn |
||||
// WithDropIndex sets the drop index option to the migration.
|
||||
// If this option is enabled, ent migration will drop old indexes
|
||||
// that were defined in the schema. This defaults to false.
|
||||
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||
// and therefore, it's recommended to enable this option to get more
|
||||
// flexibility in the schema changes.
|
||||
WithDropIndex = schema.WithDropIndex |
||||
// WithFixture sets the foreign-key renaming option to the migration when upgrading
|
||||
// ent from v0.1.0 (issue-#285). Defaults to false.
|
||||
WithFixture = schema.WithFixture |
||||
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||
WithForeignKeys = schema.WithForeignKeys |
||||
) |
||||
|
||||
// Schema is the API for creating, migrating and dropping a schema.
|
||||
type Schema struct { |
||||
drv dialect.Driver |
||||
universalID bool |
||||
} |
||||
|
||||
// NewSchema creates a new schema client.
|
||||
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } |
||||
|
||||
// Create creates all schema resources.
|
||||
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { |
||||
migrate, err := schema.NewMigrate(s.drv, opts...) |
||||
if err != nil { |
||||
return fmt.Errorf("ent/migrate: %v", err) |
||||
} |
||||
return migrate.Create(ctx, Tables...) |
||||
} |
||||
|
||||
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||
//
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
//
|
||||
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { |
||||
drv := &schema.WriteDriver{ |
||||
Writer: w, |
||||
Driver: s.drv, |
||||
} |
||||
migrate, err := schema.NewMigrate(drv, opts...) |
||||
if err != nil { |
||||
return fmt.Errorf("ent/migrate: %v", err) |
||||
} |
||||
return migrate.Create(ctx, Tables...) |
||||
} |
@ -1,105 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package migrate |
||||
|
||||
import ( |
||||
"entgo.io/ent/dialect/sql/schema" |
||||
"entgo.io/ent/schema/field" |
||||
) |
||||
|
||||
var ( |
||||
// ArticlesColumns holds the columns for the "articles" table.
|
||||
ArticlesColumns = []*schema.Column{ |
||||
{Name: "id", Type: field.TypeInt64, Increment: true}, |
||||
{Name: "title", Type: field.TypeString}, |
||||
{Name: "content", Type: field.TypeString}, |
||||
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, |
||||
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, |
||||
} |
||||
// ArticlesTable holds the schema information for the "articles" table.
|
||||
ArticlesTable = &schema.Table{ |
||||
Name: "articles", |
||||
Columns: ArticlesColumns, |
||||
PrimaryKey: []*schema.Column{ArticlesColumns[0]}, |
||||
ForeignKeys: []*schema.ForeignKey{}, |
||||
} |
||||
// CommentsColumns holds the columns for the "comments" table.
|
||||
CommentsColumns = []*schema.Column{ |
||||
{Name: "id", Type: field.TypeInt64, Increment: true}, |
||||
{Name: "name", Type: field.TypeString}, |
||||
{Name: "content", Type: field.TypeString}, |
||||
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, |
||||
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, |
||||
{Name: "article_comments", Type: field.TypeInt64, Nullable: true}, |
||||
} |
||||
// CommentsTable holds the schema information for the "comments" table.
|
||||
CommentsTable = &schema.Table{ |
||||
Name: "comments", |
||||
Columns: CommentsColumns, |
||||
PrimaryKey: []*schema.Column{CommentsColumns[0]}, |
||||
ForeignKeys: []*schema.ForeignKey{ |
||||
{ |
||||
Symbol: "comments_articles_comments", |
||||
Columns: []*schema.Column{CommentsColumns[5]}, |
||||
|
||||
RefColumns: []*schema.Column{ArticlesColumns[0]}, |
||||
OnDelete: schema.SetNull, |
||||
}, |
||||
}, |
||||
} |
||||
// TagsColumns holds the columns for the "tags" table.
|
||||
TagsColumns = []*schema.Column{ |
||||
{Name: "id", Type: field.TypeInt64, Increment: true}, |
||||
{Name: "slug", Type: field.TypeString}, |
||||
{Name: "name", Type: field.TypeString}, |
||||
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, |
||||
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, |
||||
} |
||||
// TagsTable holds the schema information for the "tags" table.
|
||||
TagsTable = &schema.Table{ |
||||
Name: "tags", |
||||
Columns: TagsColumns, |
||||
PrimaryKey: []*schema.Column{TagsColumns[0]}, |
||||
ForeignKeys: []*schema.ForeignKey{}, |
||||
} |
||||
// TagPostsColumns holds the columns for the "tag_posts" table.
|
||||
TagPostsColumns = []*schema.Column{ |
||||
{Name: "tag_id", Type: field.TypeInt64}, |
||||
{Name: "article_id", Type: field.TypeInt64}, |
||||
} |
||||
// TagPostsTable holds the schema information for the "tag_posts" table.
|
||||
TagPostsTable = &schema.Table{ |
||||
Name: "tag_posts", |
||||
Columns: TagPostsColumns, |
||||
PrimaryKey: []*schema.Column{TagPostsColumns[0], TagPostsColumns[1]}, |
||||
ForeignKeys: []*schema.ForeignKey{ |
||||
{ |
||||
Symbol: "tag_posts_tag_id", |
||||
Columns: []*schema.Column{TagPostsColumns[0]}, |
||||
|
||||
RefColumns: []*schema.Column{TagsColumns[0]}, |
||||
OnDelete: schema.Cascade, |
||||
}, |
||||
{ |
||||
Symbol: "tag_posts_article_id", |
||||
Columns: []*schema.Column{TagPostsColumns[1]}, |
||||
|
||||
RefColumns: []*schema.Column{ArticlesColumns[0]}, |
||||
OnDelete: schema.Cascade, |
||||
}, |
||||
}, |
||||
} |
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{ |
||||
ArticlesTable, |
||||
CommentsTable, |
||||
TagsTable, |
||||
TagPostsTable, |
||||
} |
||||
) |
||||
|
||||
func init() { |
||||
CommentsTable.ForeignKeys[0].RefTable = ArticlesTable |
||||
TagPostsTable.ForeignKeys[0].RefTable = TagsTable |
||||
TagPostsTable.ForeignKeys[1].RefTable = ArticlesTable |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,16 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package predicate |
||||
|
||||
import ( |
||||
"entgo.io/ent/dialect/sql" |
||||
) |
||||
|
||||
// Article is the predicate function for article builders.
|
||||
type Article func(*sql.Selector) |
||||
|
||||
// Comment is the predicate function for comment builders.
|
||||
type Comment func(*sql.Selector) |
||||
|
||||
// Tag is the predicate function for tag builders.
|
||||
type Tag func(*sql.Selector) |
@ -1,48 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/comment" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/schema" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" |
||||
) |
||||
|
||||
// The init function reads all schema descriptors with runtime code
|
||||
// (default values, validators, hooks and policies) and stitches it
|
||||
// to their package variables.
|
||||
func init() { |
||||
articleFields := schema.Article{}.Fields() |
||||
_ = articleFields |
||||
// articleDescCreatedAt is the schema descriptor for created_at field.
|
||||
articleDescCreatedAt := articleFields[3].Descriptor() |
||||
// article.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
article.DefaultCreatedAt = articleDescCreatedAt.Default.(func() time.Time) |
||||
// articleDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
articleDescUpdatedAt := articleFields[4].Descriptor() |
||||
// article.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
article.DefaultUpdatedAt = articleDescUpdatedAt.Default.(func() time.Time) |
||||
commentFields := schema.Comment{}.Fields() |
||||
_ = commentFields |
||||
// commentDescCreatedAt is the schema descriptor for created_at field.
|
||||
commentDescCreatedAt := commentFields[3].Descriptor() |
||||
// comment.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
comment.DefaultCreatedAt = commentDescCreatedAt.Default.(func() time.Time) |
||||
// commentDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
commentDescUpdatedAt := commentFields[4].Descriptor() |
||||
// comment.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
comment.DefaultUpdatedAt = commentDescUpdatedAt.Default.(func() time.Time) |
||||
tagFields := schema.Tag{}.Fields() |
||||
_ = tagFields |
||||
// tagDescCreatedAt is the schema descriptor for created_at field.
|
||||
tagDescCreatedAt := tagFields[3].Descriptor() |
||||
// tag.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
tag.DefaultCreatedAt = tagDescCreatedAt.Default.(func() time.Time) |
||||
// tagDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
tagDescUpdatedAt := tagFields[4].Descriptor() |
||||
// tag.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
tag.DefaultUpdatedAt = tagDescUpdatedAt.Default.(func() time.Time) |
||||
} |
@ -1,10 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package runtime |
||||
|
||||
// The schema-stitching logic is generated in github.com/go-kratos/kratos/examples/blog/internal/data/ent/runtime.go
|
||||
|
||||
const ( |
||||
Version = "v0.6.0" // Version of ent codegen.
|
||||
Sum = "h1:oo/a8sXPQKzHYFlVwmwOnyzBy+u8FWQsoLLqFCrOBt0=" // Sum of ent codegen.
|
||||
) |
@ -1,41 +0,0 @@ |
||||
package schema |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"entgo.io/ent" |
||||
"entgo.io/ent/dialect" |
||||
"entgo.io/ent/schema/edge" |
||||
"entgo.io/ent/schema/field" |
||||
) |
||||
|
||||
// Article holds the schema definition for the Article entity.
|
||||
type Article struct { |
||||
ent.Schema |
||||
} |
||||
|
||||
// Fields of the Post.
|
||||
func (Article) Fields() []ent.Field { |
||||
return []ent.Field{ |
||||
field.Int64("id"), |
||||
field.String("title"), |
||||
field.String("content"), |
||||
field.Time("created_at"). |
||||
Default(time.Now).SchemaType(map[string]string{ |
||||
dialect.MySQL: "datetime", |
||||
}), |
||||
field.Time("updated_at"). |
||||
Default(time.Now).SchemaType(map[string]string{ |
||||
dialect.MySQL: "datetime", |
||||
}), |
||||
} |
||||
} |
||||
|
||||
// Edges of the Post.
|
||||
func (Article) Edges() []ent.Edge { |
||||
return []ent.Edge{ |
||||
edge.To("comments", Comment.Type), |
||||
edge.From("tags", Tag.Type). |
||||
Ref("posts"), |
||||
} |
||||
} |
@ -1,41 +0,0 @@ |
||||
package schema |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"entgo.io/ent" |
||||
"entgo.io/ent/dialect" |
||||
"entgo.io/ent/schema/edge" |
||||
"entgo.io/ent/schema/field" |
||||
) |
||||
|
||||
// Comment holds the schema definition for the Comment entity.
|
||||
type Comment struct { |
||||
ent.Schema |
||||
} |
||||
|
||||
// Fields of the Comment.
|
||||
func (Comment) Fields() []ent.Field { |
||||
return []ent.Field{ |
||||
field.Int64("id"), |
||||
field.String("name"), |
||||
field.String("content"), |
||||
field.Time("created_at"). |
||||
Default(time.Now).SchemaType(map[string]string{ |
||||
dialect.MySQL: "datetime", |
||||
}), |
||||
field.Time("updated_at"). |
||||
Default(time.Now).SchemaType(map[string]string{ |
||||
dialect.MySQL: "datetime", |
||||
}), |
||||
} |
||||
} |
||||
|
||||
// Edges of the Comment.
|
||||
func (Comment) Edges() []ent.Edge { |
||||
return []ent.Edge{ |
||||
edge.From("post", Article.Type). |
||||
Ref("comments"). |
||||
Unique(), |
||||
} |
||||
} |
@ -1,39 +0,0 @@ |
||||
package schema |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"entgo.io/ent" |
||||
"entgo.io/ent/dialect" |
||||
"entgo.io/ent/schema/edge" |
||||
"entgo.io/ent/schema/field" |
||||
) |
||||
|
||||
// Tag holds the schema definition for the Tag entity.
|
||||
type Tag struct { |
||||
ent.Schema |
||||
} |
||||
|
||||
// Fields of the Tag.
|
||||
func (Tag) Fields() []ent.Field { |
||||
return []ent.Field{ |
||||
field.Int64("id"), |
||||
field.String("slug"), |
||||
field.String("name"), |
||||
field.Time("created_at"). |
||||
Default(time.Now).SchemaType(map[string]string{ |
||||
dialect.MySQL: "datetime", |
||||
}), |
||||
field.Time("updated_at"). |
||||
Default(time.Now).SchemaType(map[string]string{ |
||||
dialect.MySQL: "datetime", |
||||
}), |
||||
} |
||||
} |
||||
|
||||
// Edges of the Tag.
|
||||
func (Tag) Edges() []ent.Edge { |
||||
return []ent.Edge{ |
||||
edge.To("posts", Article.Type), |
||||
} |
||||
} |
@ -1,158 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"fmt" |
||||
"strings" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" |
||||
) |
||||
|
||||
// Tag is the model entity for the Tag schema.
|
||||
type Tag struct { |
||||
config `json:"-"` |
||||
// ID of the ent.
|
||||
ID int64 `json:"id,omitempty"` |
||||
// Slug holds the value of the "slug" field.
|
||||
Slug string `json:"slug,omitempty"` |
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"` |
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"` |
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"` |
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the TagQuery when eager-loading is set.
|
||||
Edges TagEdges `json:"edges"` |
||||
} |
||||
|
||||
// TagEdges holds the relations/edges for other nodes in the graph.
|
||||
type TagEdges struct { |
||||
// Posts holds the value of the posts edge.
|
||||
Posts []*Article `json:"posts,omitempty"` |
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool |
||||
} |
||||
|
||||
// PostsOrErr returns the Posts value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e TagEdges) PostsOrErr() ([]*Article, error) { |
||||
if e.loadedTypes[0] { |
||||
return e.Posts, nil |
||||
} |
||||
return nil, &NotLoadedError{edge: "posts"} |
||||
} |
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Tag) scanValues(columns []string) ([]interface{}, error) { |
||||
values := make([]interface{}, len(columns)) |
||||
for i := range columns { |
||||
switch columns[i] { |
||||
case tag.FieldID: |
||||
values[i] = &sql.NullInt64{} |
||||
case tag.FieldSlug, tag.FieldName: |
||||
values[i] = &sql.NullString{} |
||||
case tag.FieldCreatedAt, tag.FieldUpdatedAt: |
||||
values[i] = &sql.NullTime{} |
||||
default: |
||||
return nil, fmt.Errorf("unexpected column %q for type Tag", columns[i]) |
||||
} |
||||
} |
||||
return values, nil |
||||
} |
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Tag fields.
|
||||
func (t *Tag) assignValues(columns []string, values []interface{}) error { |
||||
if m, n := len(values), len(columns); m < n { |
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) |
||||
} |
||||
for i := range columns { |
||||
switch columns[i] { |
||||
case tag.FieldID: |
||||
value, ok := values[i].(*sql.NullInt64) |
||||
if !ok { |
||||
return fmt.Errorf("unexpected type %T for field id", value) |
||||
} |
||||
t.ID = int64(value.Int64) |
||||
case tag.FieldSlug: |
||||
if value, ok := values[i].(*sql.NullString); !ok { |
||||
return fmt.Errorf("unexpected type %T for field slug", values[i]) |
||||
} else if value.Valid { |
||||
t.Slug = value.String |
||||
} |
||||
case tag.FieldName: |
||||
if value, ok := values[i].(*sql.NullString); !ok { |
||||
return fmt.Errorf("unexpected type %T for field name", values[i]) |
||||
} else if value.Valid { |
||||
t.Name = value.String |
||||
} |
||||
case tag.FieldCreatedAt: |
||||
if value, ok := values[i].(*sql.NullTime); !ok { |
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i]) |
||||
} else if value.Valid { |
||||
t.CreatedAt = value.Time |
||||
} |
||||
case tag.FieldUpdatedAt: |
||||
if value, ok := values[i].(*sql.NullTime); !ok { |
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i]) |
||||
} else if value.Valid { |
||||
t.UpdatedAt = value.Time |
||||
} |
||||
} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
// QueryPosts queries the "posts" edge of the Tag entity.
|
||||
func (t *Tag) QueryPosts() *ArticleQuery { |
||||
return (&TagClient{config: t.config}).QueryPosts(t) |
||||
} |
||||
|
||||
// Update returns a builder for updating this Tag.
|
||||
// Note that you need to call Tag.Unwrap() before calling this method if this Tag
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (t *Tag) Update() *TagUpdateOne { |
||||
return (&TagClient{config: t.config}).UpdateOne(t) |
||||
} |
||||
|
||||
// Unwrap unwraps the Tag entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (t *Tag) Unwrap() *Tag { |
||||
tx, ok := t.config.driver.(*txDriver) |
||||
if !ok { |
||||
panic("ent: Tag is not a transactional entity") |
||||
} |
||||
t.config.driver = tx.drv |
||||
return t |
||||
} |
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (t *Tag) String() string { |
||||
var builder strings.Builder |
||||
builder.WriteString("Tag(") |
||||
builder.WriteString(fmt.Sprintf("id=%v", t.ID)) |
||||
builder.WriteString(", slug=") |
||||
builder.WriteString(t.Slug) |
||||
builder.WriteString(", name=") |
||||
builder.WriteString(t.Name) |
||||
builder.WriteString(", created_at=") |
||||
builder.WriteString(t.CreatedAt.Format(time.ANSIC)) |
||||
builder.WriteString(", updated_at=") |
||||
builder.WriteString(t.UpdatedAt.Format(time.ANSIC)) |
||||
builder.WriteByte(')') |
||||
return builder.String() |
||||
} |
||||
|
||||
// Tags is a parsable slice of Tag.
|
||||
type Tags []*Tag |
||||
|
||||
func (t Tags) config(cfg config) { |
||||
for _i := range t { |
||||
t[_i].config = cfg |
||||
} |
||||
} |
@ -1,65 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package tag |
||||
|
||||
import ( |
||||
"time" |
||||
) |
||||
|
||||
const ( |
||||
// Label holds the string label denoting the tag type in the database.
|
||||
Label = "tag" |
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id" |
||||
// FieldSlug holds the string denoting the slug field in the database.
|
||||
FieldSlug = "slug" |
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name" |
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at" |
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at" |
||||
|
||||
// EdgePosts holds the string denoting the posts edge name in mutations.
|
||||
EdgePosts = "posts" |
||||
|
||||
// Table holds the table name of the tag in the database.
|
||||
Table = "tags" |
||||
// PostsTable is the table the holds the posts relation/edge. The primary key declared below.
|
||||
PostsTable = "tag_posts" |
||||
// PostsInverseTable is the table name for the Article entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "article" package.
|
||||
PostsInverseTable = "articles" |
||||
) |
||||
|
||||
// Columns holds all SQL columns for tag fields.
|
||||
var Columns = []string{ |
||||
FieldID, |
||||
FieldSlug, |
||||
FieldName, |
||||
FieldCreatedAt, |
||||
FieldUpdatedAt, |
||||
} |
||||
|
||||
var ( |
||||
// PostsPrimaryKey and PostsColumn2 are the table columns denoting the
|
||||
// primary key for the posts relation (M2M).
|
||||
PostsPrimaryKey = []string{"tag_id", "article_id"} |
||||
) |
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool { |
||||
for i := range Columns { |
||||
if column == Columns[i] { |
||||
return true |
||||
} |
||||
} |
||||
return false |
||||
} |
||||
|
||||
var ( |
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time |
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time |
||||
) |
@ -1,556 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package tag |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
) |
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
v := make([]interface{}, len(ids)) |
||||
for i := range v { |
||||
v[i] = ids[i] |
||||
} |
||||
s.Where(sql.In(s.C(FieldID), v...)) |
||||
}) |
||||
} |
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(ids) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
v := make([]interface{}, len(ids)) |
||||
for i := range v { |
||||
v[i] = ids[i] |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldID), v...)) |
||||
}) |
||||
} |
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int64) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldID), id)) |
||||
}) |
||||
} |
||||
|
||||
// Slug applies equality check predicate on the "slug" field. It's identical to SlugEQ.
|
||||
func Slug(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugEQ applies the EQ predicate on the "slug" field.
|
||||
func SlugEQ(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugNEQ applies the NEQ predicate on the "slug" field.
|
||||
func SlugNEQ(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugIn applies the In predicate on the "slug" field.
|
||||
func SlugIn(vs ...string) predicate.Tag { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldSlug), v...)) |
||||
}) |
||||
} |
||||
|
||||
// SlugNotIn applies the NotIn predicate on the "slug" field.
|
||||
func SlugNotIn(vs ...string) predicate.Tag { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldSlug), v...)) |
||||
}) |
||||
} |
||||
|
||||
// SlugGT applies the GT predicate on the "slug" field.
|
||||
func SlugGT(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugGTE applies the GTE predicate on the "slug" field.
|
||||
func SlugGTE(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugLT applies the LT predicate on the "slug" field.
|
||||
func SlugLT(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugLTE applies the LTE predicate on the "slug" field.
|
||||
func SlugLTE(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugContains applies the Contains predicate on the "slug" field.
|
||||
func SlugContains(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.Contains(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugHasPrefix applies the HasPrefix predicate on the "slug" field.
|
||||
func SlugHasPrefix(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.HasPrefix(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugHasSuffix applies the HasSuffix predicate on the "slug" field.
|
||||
func SlugHasSuffix(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.HasSuffix(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugEqualFold applies the EqualFold predicate on the "slug" field.
|
||||
func SlugEqualFold(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EqualFold(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// SlugContainsFold applies the ContainsFold predicate on the "slug" field.
|
||||
func SlugContainsFold(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.ContainsFold(s.C(FieldSlug), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Tag { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldName), v...)) |
||||
}) |
||||
} |
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Tag { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldName), v...)) |
||||
}) |
||||
} |
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.Contains(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.HasPrefix(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.HasSuffix(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EqualFold(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.ContainsFold(s.C(FieldName), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.Tag { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldCreatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.Tag { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldCreatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.Tag { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.In(s.C(FieldUpdatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.Tag { |
||||
v := make([]interface{}, len(vs)) |
||||
for i := range v { |
||||
v[i] = vs[i] |
||||
} |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
// if not arguments were provided, append the FALSE constants,
|
||||
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||
if len(v) == 0 { |
||||
s.Where(sql.False()) |
||||
return |
||||
} |
||||
s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GT(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LT(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) |
||||
}) |
||||
} |
||||
|
||||
// HasPosts applies the HasEdge predicate on the "posts" edge.
|
||||
func HasPosts() predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(Table, FieldID), |
||||
sqlgraph.To(PostsTable, FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2M, false, PostsTable, PostsPrimaryKey...), |
||||
) |
||||
sqlgraph.HasNeighbors(s, step) |
||||
}) |
||||
} |
||||
|
||||
// HasPostsWith applies the HasEdge predicate on the "posts" edge with a given conditions (other predicates).
|
||||
func HasPostsWith(preds ...predicate.Article) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
step := sqlgraph.NewStep( |
||||
sqlgraph.From(Table, FieldID), |
||||
sqlgraph.To(PostsInverseTable, FieldID), |
||||
sqlgraph.Edge(sqlgraph.M2M, false, PostsTable, PostsPrimaryKey...), |
||||
) |
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { |
||||
for _, p := range preds { |
||||
p(s) |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Tag) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s1 := s.Clone().SetP(nil) |
||||
for _, p := range predicates { |
||||
p(s1) |
||||
} |
||||
s.Where(s1.P()) |
||||
}) |
||||
} |
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Tag) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
s1 := s.Clone().SetP(nil) |
||||
for i, p := range predicates { |
||||
if i > 0 { |
||||
s1.Or() |
||||
} |
||||
p(s1) |
||||
} |
||||
s.Where(s1.P()) |
||||
}) |
||||
} |
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Tag) predicate.Tag { |
||||
return predicate.Tag(func(s *sql.Selector) { |
||||
p(s.Not()) |
||||
}) |
||||
} |
@ -1,315 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"errors" |
||||
"fmt" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" |
||||
) |
||||
|
||||
// TagCreate is the builder for creating a Tag entity.
|
||||
type TagCreate struct { |
||||
config |
||||
mutation *TagMutation |
||||
hooks []Hook |
||||
} |
||||
|
||||
// SetSlug sets the "slug" field.
|
||||
func (tc *TagCreate) SetSlug(s string) *TagCreate { |
||||
tc.mutation.SetSlug(s) |
||||
return tc |
||||
} |
||||
|
||||
// SetName sets the "name" field.
|
||||
func (tc *TagCreate) SetName(s string) *TagCreate { |
||||
tc.mutation.SetName(s) |
||||
return tc |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (tc *TagCreate) SetCreatedAt(t time.Time) *TagCreate { |
||||
tc.mutation.SetCreatedAt(t) |
||||
return tc |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (tc *TagCreate) SetNillableCreatedAt(t *time.Time) *TagCreate { |
||||
if t != nil { |
||||
tc.SetCreatedAt(*t) |
||||
} |
||||
return tc |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (tc *TagCreate) SetUpdatedAt(t time.Time) *TagCreate { |
||||
tc.mutation.SetUpdatedAt(t) |
||||
return tc |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (tc *TagCreate) SetNillableUpdatedAt(t *time.Time) *TagCreate { |
||||
if t != nil { |
||||
tc.SetUpdatedAt(*t) |
||||
} |
||||
return tc |
||||
} |
||||
|
||||
// SetID sets the "id" field.
|
||||
func (tc *TagCreate) SetID(i int64) *TagCreate { |
||||
tc.mutation.SetID(i) |
||||
return tc |
||||
} |
||||
|
||||
// AddPostIDs adds the "posts" edge to the Article entity by IDs.
|
||||
func (tc *TagCreate) AddPostIDs(ids ...int64) *TagCreate { |
||||
tc.mutation.AddPostIDs(ids...) |
||||
return tc |
||||
} |
||||
|
||||
// AddPosts adds the "posts" edges to the Article entity.
|
||||
func (tc *TagCreate) AddPosts(a ...*Article) *TagCreate { |
||||
ids := make([]int64, len(a)) |
||||
for i := range a { |
||||
ids[i] = a[i].ID |
||||
} |
||||
return tc.AddPostIDs(ids...) |
||||
} |
||||
|
||||
// Mutation returns the TagMutation object of the builder.
|
||||
func (tc *TagCreate) Mutation() *TagMutation { |
||||
return tc.mutation |
||||
} |
||||
|
||||
// Save creates the Tag in the database.
|
||||
func (tc *TagCreate) Save(ctx context.Context) (*Tag, error) { |
||||
var ( |
||||
err error |
||||
node *Tag |
||||
) |
||||
tc.defaults() |
||||
if len(tc.hooks) == 0 { |
||||
if err = tc.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
node, err = tc.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*TagMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
if err = tc.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
tc.mutation = mutation |
||||
node, err = tc.sqlSave(ctx) |
||||
mutation.done = true |
||||
return node, err |
||||
}) |
||||
for i := len(tc.hooks) - 1; i >= 0; i-- { |
||||
mut = tc.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, tc.mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return node, err |
||||
} |
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (tc *TagCreate) SaveX(ctx context.Context) *Tag { |
||||
v, err := tc.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (tc *TagCreate) defaults() { |
||||
if _, ok := tc.mutation.CreatedAt(); !ok { |
||||
v := tag.DefaultCreatedAt() |
||||
tc.mutation.SetCreatedAt(v) |
||||
} |
||||
if _, ok := tc.mutation.UpdatedAt(); !ok { |
||||
v := tag.DefaultUpdatedAt() |
||||
tc.mutation.SetUpdatedAt(v) |
||||
} |
||||
} |
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (tc *TagCreate) check() error { |
||||
if _, ok := tc.mutation.Slug(); !ok { |
||||
return &ValidationError{Name: "slug", err: errors.New("ent: missing required field \"slug\"")} |
||||
} |
||||
if _, ok := tc.mutation.Name(); !ok { |
||||
return &ValidationError{Name: "name", err: errors.New("ent: missing required field \"name\"")} |
||||
} |
||||
if _, ok := tc.mutation.CreatedAt(); !ok { |
||||
return &ValidationError{Name: "created_at", err: errors.New("ent: missing required field \"created_at\"")} |
||||
} |
||||
if _, ok := tc.mutation.UpdatedAt(); !ok { |
||||
return &ValidationError{Name: "updated_at", err: errors.New("ent: missing required field \"updated_at\"")} |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (tc *TagCreate) sqlSave(ctx context.Context) (*Tag, error) { |
||||
_node, _spec := tc.createSpec() |
||||
if err := sqlgraph.CreateNode(ctx, tc.driver, _spec); err != nil { |
||||
if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return nil, err |
||||
} |
||||
if _node.ID == 0 { |
||||
id := _spec.ID.Value.(int64) |
||||
_node.ID = int64(id) |
||||
} |
||||
return _node, nil |
||||
} |
||||
|
||||
func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { |
||||
var ( |
||||
_node = &Tag{config: tc.config} |
||||
_spec = &sqlgraph.CreateSpec{ |
||||
Table: tag.Table, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
} |
||||
) |
||||
if id, ok := tc.mutation.ID(); ok { |
||||
_node.ID = id |
||||
_spec.ID.Value = id |
||||
} |
||||
if value, ok := tc.mutation.Slug(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: tag.FieldSlug, |
||||
}) |
||||
_node.Slug = value |
||||
} |
||||
if value, ok := tc.mutation.Name(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: tag.FieldName, |
||||
}) |
||||
_node.Name = value |
||||
} |
||||
if value, ok := tc.mutation.CreatedAt(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: tag.FieldCreatedAt, |
||||
}) |
||||
_node.CreatedAt = value |
||||
} |
||||
if value, ok := tc.mutation.UpdatedAt(); ok { |
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: tag.FieldUpdatedAt, |
||||
}) |
||||
_node.UpdatedAt = value |
||||
} |
||||
if nodes := tc.mutation.PostsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: false, |
||||
Table: tag.PostsTable, |
||||
Columns: tag.PostsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges = append(_spec.Edges, edge) |
||||
} |
||||
return _node, _spec |
||||
} |
||||
|
||||
// TagCreateBulk is the builder for creating many Tag entities in bulk.
|
||||
type TagCreateBulk struct { |
||||
config |
||||
builders []*TagCreate |
||||
} |
||||
|
||||
// Save creates the Tag entities in the database.
|
||||
func (tcb *TagCreateBulk) Save(ctx context.Context) ([]*Tag, error) { |
||||
specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) |
||||
nodes := make([]*Tag, len(tcb.builders)) |
||||
mutators := make([]Mutator, len(tcb.builders)) |
||||
for i := range tcb.builders { |
||||
func(i int, root context.Context) { |
||||
builder := tcb.builders[i] |
||||
builder.defaults() |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*TagMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
if err := builder.check(); err != nil { |
||||
return nil, err |
||||
} |
||||
builder.mutation = mutation |
||||
nodes[i], specs[i] = builder.createSpec() |
||||
var err error |
||||
if i < len(mutators)-1 { |
||||
_, err = mutators[i+1].Mutate(root, tcb.builders[i+1].mutation) |
||||
} else { |
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, tcb.driver, &sqlgraph.BatchCreateSpec{Nodes: specs}); err != nil { |
||||
if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
} |
||||
} |
||||
mutation.done = true |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
if nodes[i].ID == 0 { |
||||
id := specs[i].ID.Value.(int64) |
||||
nodes[i].ID = int64(id) |
||||
} |
||||
return nodes[i], nil |
||||
}) |
||||
for i := len(builder.hooks) - 1; i >= 0; i-- { |
||||
mut = builder.hooks[i](mut) |
||||
} |
||||
mutators[i] = mut |
||||
}(i, ctx) |
||||
} |
||||
if len(mutators) > 0 { |
||||
if _, err := mutators[0].Mutate(ctx, tcb.builders[0].mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return nodes, nil |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tcb *TagCreateBulk) SaveX(ctx context.Context) []*Tag { |
||||
v, err := tcb.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return v |
||||
} |
@ -1,108 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" |
||||
) |
||||
|
||||
// TagDelete is the builder for deleting a Tag entity.
|
||||
type TagDelete struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *TagMutation |
||||
} |
||||
|
||||
// Where adds a new predicate to the TagDelete builder.
|
||||
func (td *TagDelete) Where(ps ...predicate.Tag) *TagDelete { |
||||
td.mutation.predicates = append(td.mutation.predicates, ps...) |
||||
return td |
||||
} |
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (td *TagDelete) Exec(ctx context.Context) (int, error) { |
||||
var ( |
||||
err error |
||||
affected int |
||||
) |
||||
if len(td.hooks) == 0 { |
||||
affected, err = td.sqlExec(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*TagMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
td.mutation = mutation |
||||
affected, err = td.sqlExec(ctx) |
||||
mutation.done = true |
||||
return affected, err |
||||
}) |
||||
for i := len(td.hooks) - 1; i >= 0; i-- { |
||||
mut = td.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, td.mutation); err != nil { |
||||
return 0, err |
||||
} |
||||
} |
||||
return affected, err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (td *TagDelete) ExecX(ctx context.Context) int { |
||||
n, err := td.Exec(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return n |
||||
} |
||||
|
||||
func (td *TagDelete) sqlExec(ctx context.Context) (int, error) { |
||||
_spec := &sqlgraph.DeleteSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: tag.Table, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
if ps := td.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
return sqlgraph.DeleteNodes(ctx, td.driver, _spec) |
||||
} |
||||
|
||||
// TagDeleteOne is the builder for deleting a single Tag entity.
|
||||
type TagDeleteOne struct { |
||||
td *TagDelete |
||||
} |
||||
|
||||
// Exec executes the deletion query.
|
||||
func (tdo *TagDeleteOne) Exec(ctx context.Context) error { |
||||
n, err := tdo.td.Exec(ctx) |
||||
switch { |
||||
case err != nil: |
||||
return err |
||||
case n == 0: |
||||
return &NotFoundError{tag.Label} |
||||
default: |
||||
return nil |
||||
} |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tdo *TagDeleteOne) ExecX(ctx context.Context) { |
||||
tdo.td.ExecX(ctx) |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,530 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"time" |
||||
|
||||
"entgo.io/ent/dialect/sql" |
||||
"entgo.io/ent/dialect/sql/sqlgraph" |
||||
"entgo.io/ent/schema/field" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/article" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/predicate" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/data/ent/tag" |
||||
) |
||||
|
||||
// TagUpdate is the builder for updating Tag entities.
|
||||
type TagUpdate struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *TagMutation |
||||
} |
||||
|
||||
// Where adds a new predicate for the TagUpdate builder.
|
||||
func (tu *TagUpdate) Where(ps ...predicate.Tag) *TagUpdate { |
||||
tu.mutation.predicates = append(tu.mutation.predicates, ps...) |
||||
return tu |
||||
} |
||||
|
||||
// SetSlug sets the "slug" field.
|
||||
func (tu *TagUpdate) SetSlug(s string) *TagUpdate { |
||||
tu.mutation.SetSlug(s) |
||||
return tu |
||||
} |
||||
|
||||
// SetName sets the "name" field.
|
||||
func (tu *TagUpdate) SetName(s string) *TagUpdate { |
||||
tu.mutation.SetName(s) |
||||
return tu |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (tu *TagUpdate) SetCreatedAt(t time.Time) *TagUpdate { |
||||
tu.mutation.SetCreatedAt(t) |
||||
return tu |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (tu *TagUpdate) SetNillableCreatedAt(t *time.Time) *TagUpdate { |
||||
if t != nil { |
||||
tu.SetCreatedAt(*t) |
||||
} |
||||
return tu |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (tu *TagUpdate) SetUpdatedAt(t time.Time) *TagUpdate { |
||||
tu.mutation.SetUpdatedAt(t) |
||||
return tu |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (tu *TagUpdate) SetNillableUpdatedAt(t *time.Time) *TagUpdate { |
||||
if t != nil { |
||||
tu.SetUpdatedAt(*t) |
||||
} |
||||
return tu |
||||
} |
||||
|
||||
// AddPostIDs adds the "posts" edge to the Article entity by IDs.
|
||||
func (tu *TagUpdate) AddPostIDs(ids ...int64) *TagUpdate { |
||||
tu.mutation.AddPostIDs(ids...) |
||||
return tu |
||||
} |
||||
|
||||
// AddPosts adds the "posts" edges to the Article entity.
|
||||
func (tu *TagUpdate) AddPosts(a ...*Article) *TagUpdate { |
||||
ids := make([]int64, len(a)) |
||||
for i := range a { |
||||
ids[i] = a[i].ID |
||||
} |
||||
return tu.AddPostIDs(ids...) |
||||
} |
||||
|
||||
// Mutation returns the TagMutation object of the builder.
|
||||
func (tu *TagUpdate) Mutation() *TagMutation { |
||||
return tu.mutation |
||||
} |
||||
|
||||
// ClearPosts clears all "posts" edges to the Article entity.
|
||||
func (tu *TagUpdate) ClearPosts() *TagUpdate { |
||||
tu.mutation.ClearPosts() |
||||
return tu |
||||
} |
||||
|
||||
// RemovePostIDs removes the "posts" edge to Article entities by IDs.
|
||||
func (tu *TagUpdate) RemovePostIDs(ids ...int64) *TagUpdate { |
||||
tu.mutation.RemovePostIDs(ids...) |
||||
return tu |
||||
} |
||||
|
||||
// RemovePosts removes "posts" edges to Article entities.
|
||||
func (tu *TagUpdate) RemovePosts(a ...*Article) *TagUpdate { |
||||
ids := make([]int64, len(a)) |
||||
for i := range a { |
||||
ids[i] = a[i].ID |
||||
} |
||||
return tu.RemovePostIDs(ids...) |
||||
} |
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (tu *TagUpdate) Save(ctx context.Context) (int, error) { |
||||
var ( |
||||
err error |
||||
affected int |
||||
) |
||||
if len(tu.hooks) == 0 { |
||||
affected, err = tu.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*TagMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
tu.mutation = mutation |
||||
affected, err = tu.sqlSave(ctx) |
||||
mutation.done = true |
||||
return affected, err |
||||
}) |
||||
for i := len(tu.hooks) - 1; i >= 0; i-- { |
||||
mut = tu.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, tu.mutation); err != nil { |
||||
return 0, err |
||||
} |
||||
} |
||||
return affected, err |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tu *TagUpdate) SaveX(ctx context.Context) int { |
||||
affected, err := tu.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return affected |
||||
} |
||||
|
||||
// Exec executes the query.
|
||||
func (tu *TagUpdate) Exec(ctx context.Context) error { |
||||
_, err := tu.Save(ctx) |
||||
return err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tu *TagUpdate) ExecX(ctx context.Context) { |
||||
if err := tu.Exec(ctx); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
||||
|
||||
func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { |
||||
_spec := &sqlgraph.UpdateSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: tag.Table, |
||||
Columns: tag.Columns, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
if ps := tu.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
if value, ok := tu.mutation.Slug(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: tag.FieldSlug, |
||||
}) |
||||
} |
||||
if value, ok := tu.mutation.Name(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: tag.FieldName, |
||||
}) |
||||
} |
||||
if value, ok := tu.mutation.CreatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: tag.FieldCreatedAt, |
||||
}) |
||||
} |
||||
if value, ok := tu.mutation.UpdatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: tag.FieldUpdatedAt, |
||||
}) |
||||
} |
||||
if tu.mutation.PostsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: false, |
||||
Table: tag.PostsTable, |
||||
Columns: tag.PostsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := tu.mutation.RemovedPostsIDs(); len(nodes) > 0 && !tu.mutation.PostsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: false, |
||||
Table: tag.PostsTable, |
||||
Columns: tag.PostsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := tu.mutation.PostsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: false, |
||||
Table: tag.PostsTable, |
||||
Columns: tag.PostsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge) |
||||
} |
||||
if n, err = sqlgraph.UpdateNodes(ctx, tu.driver, _spec); err != nil { |
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
||||
err = &NotFoundError{tag.Label} |
||||
} else if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return 0, err |
||||
} |
||||
return n, nil |
||||
} |
||||
|
||||
// TagUpdateOne is the builder for updating a single Tag entity.
|
||||
type TagUpdateOne struct { |
||||
config |
||||
hooks []Hook |
||||
mutation *TagMutation |
||||
} |
||||
|
||||
// SetSlug sets the "slug" field.
|
||||
func (tuo *TagUpdateOne) SetSlug(s string) *TagUpdateOne { |
||||
tuo.mutation.SetSlug(s) |
||||
return tuo |
||||
} |
||||
|
||||
// SetName sets the "name" field.
|
||||
func (tuo *TagUpdateOne) SetName(s string) *TagUpdateOne { |
||||
tuo.mutation.SetName(s) |
||||
return tuo |
||||
} |
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (tuo *TagUpdateOne) SetCreatedAt(t time.Time) *TagUpdateOne { |
||||
tuo.mutation.SetCreatedAt(t) |
||||
return tuo |
||||
} |
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (tuo *TagUpdateOne) SetNillableCreatedAt(t *time.Time) *TagUpdateOne { |
||||
if t != nil { |
||||
tuo.SetCreatedAt(*t) |
||||
} |
||||
return tuo |
||||
} |
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (tuo *TagUpdateOne) SetUpdatedAt(t time.Time) *TagUpdateOne { |
||||
tuo.mutation.SetUpdatedAt(t) |
||||
return tuo |
||||
} |
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (tuo *TagUpdateOne) SetNillableUpdatedAt(t *time.Time) *TagUpdateOne { |
||||
if t != nil { |
||||
tuo.SetUpdatedAt(*t) |
||||
} |
||||
return tuo |
||||
} |
||||
|
||||
// AddPostIDs adds the "posts" edge to the Article entity by IDs.
|
||||
func (tuo *TagUpdateOne) AddPostIDs(ids ...int64) *TagUpdateOne { |
||||
tuo.mutation.AddPostIDs(ids...) |
||||
return tuo |
||||
} |
||||
|
||||
// AddPosts adds the "posts" edges to the Article entity.
|
||||
func (tuo *TagUpdateOne) AddPosts(a ...*Article) *TagUpdateOne { |
||||
ids := make([]int64, len(a)) |
||||
for i := range a { |
||||
ids[i] = a[i].ID |
||||
} |
||||
return tuo.AddPostIDs(ids...) |
||||
} |
||||
|
||||
// Mutation returns the TagMutation object of the builder.
|
||||
func (tuo *TagUpdateOne) Mutation() *TagMutation { |
||||
return tuo.mutation |
||||
} |
||||
|
||||
// ClearPosts clears all "posts" edges to the Article entity.
|
||||
func (tuo *TagUpdateOne) ClearPosts() *TagUpdateOne { |
||||
tuo.mutation.ClearPosts() |
||||
return tuo |
||||
} |
||||
|
||||
// RemovePostIDs removes the "posts" edge to Article entities by IDs.
|
||||
func (tuo *TagUpdateOne) RemovePostIDs(ids ...int64) *TagUpdateOne { |
||||
tuo.mutation.RemovePostIDs(ids...) |
||||
return tuo |
||||
} |
||||
|
||||
// RemovePosts removes "posts" edges to Article entities.
|
||||
func (tuo *TagUpdateOne) RemovePosts(a ...*Article) *TagUpdateOne { |
||||
ids := make([]int64, len(a)) |
||||
for i := range a { |
||||
ids[i] = a[i].ID |
||||
} |
||||
return tuo.RemovePostIDs(ids...) |
||||
} |
||||
|
||||
// Save executes the query and returns the updated Tag entity.
|
||||
func (tuo *TagUpdateOne) Save(ctx context.Context) (*Tag, error) { |
||||
var ( |
||||
err error |
||||
node *Tag |
||||
) |
||||
if len(tuo.hooks) == 0 { |
||||
node, err = tuo.sqlSave(ctx) |
||||
} else { |
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||
mutation, ok := m.(*TagMutation) |
||||
if !ok { |
||||
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||
} |
||||
tuo.mutation = mutation |
||||
node, err = tuo.sqlSave(ctx) |
||||
mutation.done = true |
||||
return node, err |
||||
}) |
||||
for i := len(tuo.hooks) - 1; i >= 0; i-- { |
||||
mut = tuo.hooks[i](mut) |
||||
} |
||||
if _, err := mut.Mutate(ctx, tuo.mutation); err != nil { |
||||
return nil, err |
||||
} |
||||
} |
||||
return node, err |
||||
} |
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tuo *TagUpdateOne) SaveX(ctx context.Context) *Tag { |
||||
node, err := tuo.Save(ctx) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
return node |
||||
} |
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (tuo *TagUpdateOne) Exec(ctx context.Context) error { |
||||
_, err := tuo.Save(ctx) |
||||
return err |
||||
} |
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tuo *TagUpdateOne) ExecX(ctx context.Context) { |
||||
if err := tuo.Exec(ctx); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
||||
|
||||
func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { |
||||
_spec := &sqlgraph.UpdateSpec{ |
||||
Node: &sqlgraph.NodeSpec{ |
||||
Table: tag.Table, |
||||
Columns: tag.Columns, |
||||
ID: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: tag.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
id, ok := tuo.mutation.ID() |
||||
if !ok { |
||||
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Tag.ID for update")} |
||||
} |
||||
_spec.Node.ID.Value = id |
||||
if ps := tuo.mutation.predicates; len(ps) > 0 { |
||||
_spec.Predicate = func(selector *sql.Selector) { |
||||
for i := range ps { |
||||
ps[i](selector) |
||||
} |
||||
} |
||||
} |
||||
if value, ok := tuo.mutation.Slug(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: tag.FieldSlug, |
||||
}) |
||||
} |
||||
if value, ok := tuo.mutation.Name(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeString, |
||||
Value: value, |
||||
Column: tag.FieldName, |
||||
}) |
||||
} |
||||
if value, ok := tuo.mutation.CreatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: tag.FieldCreatedAt, |
||||
}) |
||||
} |
||||
if value, ok := tuo.mutation.UpdatedAt(); ok { |
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ |
||||
Type: field.TypeTime, |
||||
Value: value, |
||||
Column: tag.FieldUpdatedAt, |
||||
}) |
||||
} |
||||
if tuo.mutation.PostsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: false, |
||||
Table: tag.PostsTable, |
||||
Columns: tag.PostsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := tuo.mutation.RemovedPostsIDs(); len(nodes) > 0 && !tuo.mutation.PostsCleared() { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: false, |
||||
Table: tag.PostsTable, |
||||
Columns: tag.PostsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge) |
||||
} |
||||
if nodes := tuo.mutation.PostsIDs(); len(nodes) > 0 { |
||||
edge := &sqlgraph.EdgeSpec{ |
||||
Rel: sqlgraph.M2M, |
||||
Inverse: false, |
||||
Table: tag.PostsTable, |
||||
Columns: tag.PostsPrimaryKey, |
||||
Bidi: false, |
||||
Target: &sqlgraph.EdgeTarget{ |
||||
IDSpec: &sqlgraph.FieldSpec{ |
||||
Type: field.TypeInt64, |
||||
Column: article.FieldID, |
||||
}, |
||||
}, |
||||
} |
||||
for _, k := range nodes { |
||||
edge.Target.Nodes = append(edge.Target.Nodes, k) |
||||
} |
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge) |
||||
} |
||||
_node = &Tag{config: tuo.config} |
||||
_spec.Assign = _node.assignValues |
||||
_spec.ScanValues = _node.scanValues |
||||
if err = sqlgraph.UpdateNode(ctx, tuo.driver, _spec); err != nil { |
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
||||
err = &NotFoundError{tag.Label} |
||||
} else if cerr, ok := isSQLConstraintError(err); ok { |
||||
err = cerr |
||||
} |
||||
return nil, err |
||||
} |
||||
return _node, nil |
||||
} |
@ -1,216 +0,0 @@ |
||||
// Code generated by entc, DO NOT EDIT.
|
||||
|
||||
package ent |
||||
|
||||
import ( |
||||
"context" |
||||
"sync" |
||||
|
||||
"entgo.io/ent/dialect" |
||||
) |
||||
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct { |
||||
config |
||||
// Article is the client for interacting with the Article builders.
|
||||
Article *ArticleClient |
||||
// Comment is the client for interacting with the Comment builders.
|
||||
Comment *CommentClient |
||||
// Tag is the client for interacting with the Tag builders.
|
||||
Tag *TagClient |
||||
|
||||
// lazily loaded.
|
||||
client *Client |
||||
clientOnce sync.Once |
||||
|
||||
// completion callbacks.
|
||||
mu sync.Mutex |
||||
onCommit []CommitHook |
||||
onRollback []RollbackHook |
||||
|
||||
// ctx lives for the life of the transaction. It is
|
||||
// the same context used by the underlying connection.
|
||||
ctx context.Context |
||||
} |
||||
|
||||
type ( |
||||
// Committer is the interface that wraps the Committer method.
|
||||
Committer interface { |
||||
Commit(context.Context, *Tx) error |
||||
} |
||||
|
||||
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Committer. If f is a function with the appropriate
|
||||
// signature, CommitFunc(f) is a Committer that calls f.
|
||||
CommitFunc func(context.Context, *Tx) error |
||||
|
||||
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||
// and returns a Committer. For example:
|
||||
//
|
||||
// hook := func(next ent.Committer) ent.Committer {
|
||||
// return ent.CommitFunc(func(context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Commit(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
CommitHook func(Committer) Committer |
||||
) |
||||
|
||||
// Commit calls f(ctx, m).
|
||||
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { |
||||
return f(ctx, tx) |
||||
} |
||||
|
||||
// Commit commits the transaction.
|
||||
func (tx *Tx) Commit() error { |
||||
txDriver := tx.config.driver.(*txDriver) |
||||
var fn Committer = CommitFunc(func(context.Context, *Tx) error { |
||||
return txDriver.tx.Commit() |
||||
}) |
||||
tx.mu.Lock() |
||||
hooks := append([]CommitHook(nil), tx.onCommit...) |
||||
tx.mu.Unlock() |
||||
for i := len(hooks) - 1; i >= 0; i-- { |
||||
fn = hooks[i](fn) |
||||
} |
||||
return fn.Commit(tx.ctx, tx) |
||||
} |
||||
|
||||
// OnCommit adds a hook to call on commit.
|
||||
func (tx *Tx) OnCommit(f CommitHook) { |
||||
tx.mu.Lock() |
||||
defer tx.mu.Unlock() |
||||
tx.onCommit = append(tx.onCommit, f) |
||||
} |
||||
|
||||
type ( |
||||
// Rollbacker is the interface that wraps the Rollbacker method.
|
||||
Rollbacker interface { |
||||
Rollback(context.Context, *Tx) error |
||||
} |
||||
|
||||
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Rollbacker. If f is a function with the appropriate
|
||||
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||
RollbackFunc func(context.Context, *Tx) error |
||||
|
||||
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||
// and returns a Rollbacker. For example:
|
||||
//
|
||||
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||
// return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Rollback(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
RollbackHook func(Rollbacker) Rollbacker |
||||
) |
||||
|
||||
// Rollback calls f(ctx, m).
|
||||
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { |
||||
return f(ctx, tx) |
||||
} |
||||
|
||||
// Rollback rollbacks the transaction.
|
||||
func (tx *Tx) Rollback() error { |
||||
txDriver := tx.config.driver.(*txDriver) |
||||
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { |
||||
return txDriver.tx.Rollback() |
||||
}) |
||||
tx.mu.Lock() |
||||
hooks := append([]RollbackHook(nil), tx.onRollback...) |
||||
tx.mu.Unlock() |
||||
for i := len(hooks) - 1; i >= 0; i-- { |
||||
fn = hooks[i](fn) |
||||
} |
||||
return fn.Rollback(tx.ctx, tx) |
||||
} |
||||
|
||||
// OnRollback adds a hook to call on rollback.
|
||||
func (tx *Tx) OnRollback(f RollbackHook) { |
||||
tx.mu.Lock() |
||||
defer tx.mu.Unlock() |
||||
tx.onRollback = append(tx.onRollback, f) |
||||
} |
||||
|
||||
// Client returns a Client that binds to current transaction.
|
||||
func (tx *Tx) Client() *Client { |
||||
tx.clientOnce.Do(func() { |
||||
tx.client = &Client{config: tx.config} |
||||
tx.client.init() |
||||
}) |
||||
return tx.client |
||||
} |
||||
|
||||
func (tx *Tx) init() { |
||||
tx.Article = NewArticleClient(tx.config) |
||||
tx.Comment = NewCommentClient(tx.config) |
||||
tx.Tag = NewTagClient(tx.config) |
||||
} |
||||
|
||||
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||
// The idea is to support transactions without adding any extra code to the builders.
|
||||
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: Article.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
type txDriver struct { |
||||
// the driver we started the transaction from.
|
||||
drv dialect.Driver |
||||
// tx is the underlying transaction.
|
||||
tx dialect.Tx |
||||
} |
||||
|
||||
// newTx creates a new transactional driver.
|
||||
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { |
||||
tx, err := drv.Tx(ctx) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return &txDriver{tx: tx, drv: drv}, nil |
||||
} |
||||
|
||||
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||
// from the internal builders. Should be called only by the internal builders.
|
||||
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } |
||||
|
||||
// Dialect returns the dialect of the driver we started the transaction from.
|
||||
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } |
||||
|
||||
// Close is a nop close.
|
||||
func (*txDriver) Close() error { return nil } |
||||
|
||||
// Commit is a nop commit for the internal builders.
|
||||
// User must call `Tx.Commit` in order to commit the transaction.
|
||||
func (*txDriver) Commit() error { return nil } |
||||
|
||||
// Rollback is a nop rollback for the internal builders.
|
||||
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||
func (*txDriver) Rollback() error { return nil } |
||||
|
||||
// Exec calls tx.Exec.
|
||||
func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error { |
||||
return tx.tx.Exec(ctx, query, args, v) |
||||
} |
||||
|
||||
// Query calls tx.Query.
|
||||
func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error { |
||||
return tx.tx.Query(ctx, query, args, v) |
||||
} |
||||
|
||||
var _ dialect.Driver = (*txDriver)(nil) |
@ -1,26 +0,0 @@ |
||||
package data |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
|
||||
"github.com/go-redis/redis/v8" |
||||
) |
||||
|
||||
func likeKey(id int64) string { |
||||
return fmt.Sprintf("like:%d", id) |
||||
} |
||||
|
||||
func (ar *articleRepo) GetArticleLike(ctx context.Context, id int64) (rv int64, err error) { |
||||
get := ar.data.rdb.Get(ctx, likeKey(id)) |
||||
rv, err = get.Int64() |
||||
if err == redis.Nil { |
||||
return 0, nil |
||||
} |
||||
return |
||||
} |
||||
|
||||
func (ar *articleRepo) IncArticleLike(ctx context.Context, id int64) error { |
||||
_, err := ar.data.rdb.Incr(ctx, likeKey(id)).Result() |
||||
return err |
||||
} |
@ -1,37 +0,0 @@ |
||||
package server |
||||
|
||||
import ( |
||||
v1 "github.com/go-kratos/kratos/examples/blog/api/blog/v1" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/conf" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/service" |
||||
"github.com/go-kratos/kratos/v2/log" |
||||
"github.com/go-kratos/kratos/v2/middleware/logging" |
||||
"github.com/go-kratos/kratos/v2/middleware/recovery" |
||||
"github.com/go-kratos/kratos/v2/middleware/tracing" |
||||
"github.com/go-kratos/kratos/v2/middleware/validate" |
||||
"github.com/go-kratos/kratos/v2/transport/grpc" |
||||
) |
||||
|
||||
// NewGRPCServer new a gRPC server.
|
||||
func NewGRPCServer(c *conf.Server, logger log.Logger, blog *service.BlogService) *grpc.Server { |
||||
opts := []grpc.ServerOption{ |
||||
grpc.Middleware( |
||||
recovery.Recovery(), |
||||
tracing.Server(), |
||||
logging.Server(logger), |
||||
validate.Validator(), |
||||
), |
||||
} |
||||
if c.Grpc.Network != "" { |
||||
opts = append(opts, grpc.Network(c.Grpc.Network)) |
||||
} |
||||
if c.Grpc.Addr != "" { |
||||
opts = append(opts, grpc.Address(c.Grpc.Addr)) |
||||
} |
||||
if c.Grpc.Timeout != nil { |
||||
opts = append(opts, grpc.Timeout(c.Grpc.Timeout.AsDuration())) |
||||
} |
||||
srv := grpc.NewServer(opts...) |
||||
v1.RegisterBlogServiceServer(srv, blog) |
||||
return srv |
||||
} |
@ -1,37 +0,0 @@ |
||||
package server |
||||
|
||||
import ( |
||||
v1 "github.com/go-kratos/kratos/examples/blog/api/blog/v1" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/conf" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/service" |
||||
"github.com/go-kratos/kratos/v2/log" |
||||
"github.com/go-kratos/kratos/v2/middleware/logging" |
||||
"github.com/go-kratos/kratos/v2/middleware/recovery" |
||||
"github.com/go-kratos/kratos/v2/middleware/tracing" |
||||
"github.com/go-kratos/kratos/v2/middleware/validate" |
||||
"github.com/go-kratos/kratos/v2/transport/http" |
||||
) |
||||
|
||||
// NewHTTPServer new a HTTP server.
|
||||
func NewHTTPServer(c *conf.Server, logger log.Logger, blog *service.BlogService) *http.Server { |
||||
opts := []http.ServerOption{ |
||||
http.Middleware( |
||||
recovery.Recovery(), |
||||
tracing.Server(), |
||||
logging.Server(logger), |
||||
validate.Validator(), |
||||
), |
||||
} |
||||
if c.Http.Network != "" { |
||||
opts = append(opts, http.Network(c.Http.Network)) |
||||
} |
||||
if c.Http.Addr != "" { |
||||
opts = append(opts, http.Address(c.Http.Addr)) |
||||
} |
||||
if c.Http.Timeout != nil { |
||||
opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration())) |
||||
} |
||||
srv := http.NewServer(opts...) |
||||
v1.RegisterBlogServiceHTTPServer(srv, blog) |
||||
return srv |
||||
} |
@ -1,8 +0,0 @@ |
||||
package server |
||||
|
||||
import ( |
||||
"github.com/google/wire" |
||||
) |
||||
|
||||
// ProviderSet is server providers.
|
||||
var ProviderSet = wire.NewSet(NewHTTPServer, NewGRPCServer) |
@ -1 +0,0 @@ |
||||
# Service |
@ -1,67 +0,0 @@ |
||||
package service |
||||
|
||||
import ( |
||||
"context" |
||||
|
||||
"go.opentelemetry.io/otel" |
||||
|
||||
pb "github.com/go-kratos/kratos/examples/blog/api/blog/v1" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/biz" |
||||
|
||||
"github.com/go-kratos/kratos/v2/log" |
||||
) |
||||
|
||||
func NewBlogService(article *biz.ArticleUsecase, logger log.Logger) *BlogService { |
||||
return &BlogService{ |
||||
article: article, |
||||
log: log.NewHelper(logger), |
||||
} |
||||
} |
||||
|
||||
func (s *BlogService) CreateArticle(ctx context.Context, req *pb.CreateArticleRequest) (*pb.CreateArticleReply, error) { |
||||
s.log.Infof("input data %v", req) |
||||
err := s.article.Create(ctx, &biz.Article{ |
||||
Title: req.Title, |
||||
Content: req.Content, |
||||
}) |
||||
return &pb.CreateArticleReply{}, err |
||||
} |
||||
|
||||
func (s *BlogService) UpdateArticle(ctx context.Context, req *pb.UpdateArticleRequest) (*pb.UpdateArticleReply, error) { |
||||
s.log.Infof("input data %v", req) |
||||
err := s.article.Update(ctx, req.Id, &biz.Article{ |
||||
Title: req.Title, |
||||
Content: req.Content, |
||||
}) |
||||
return &pb.UpdateArticleReply{}, err |
||||
} |
||||
|
||||
func (s *BlogService) DeleteArticle(ctx context.Context, req *pb.DeleteArticleRequest) (*pb.DeleteArticleReply, error) { |
||||
s.log.Infof("input data %v", req) |
||||
err := s.article.Delete(ctx, req.Id) |
||||
return &pb.DeleteArticleReply{}, err |
||||
} |
||||
|
||||
func (s *BlogService) GetArticle(ctx context.Context, req *pb.GetArticleRequest) (*pb.GetArticleReply, error) { |
||||
tr := otel.Tracer("api") |
||||
ctx, span := tr.Start(ctx, "GetArticle") |
||||
defer span.End() |
||||
p, err := s.article.Get(ctx, req.Id) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
return &pb.GetArticleReply{Article: &pb.Article{Id: p.ID, Title: p.Title, Content: p.Content, Like: p.Like}}, nil |
||||
} |
||||
|
||||
func (s *BlogService) ListArticle(ctx context.Context, req *pb.ListArticleRequest) (*pb.ListArticleReply, error) { |
||||
ps, err := s.article.List(ctx) |
||||
reply := &pb.ListArticleReply{} |
||||
for _, p := range ps { |
||||
reply.Results = append(reply.Results, &pb.Article{ |
||||
Id: p.ID, |
||||
Title: p.Title, |
||||
Content: p.Content, |
||||
}) |
||||
} |
||||
return reply, err |
||||
} |
@ -1,20 +0,0 @@ |
||||
package service |
||||
|
||||
import ( |
||||
pb "github.com/go-kratos/kratos/examples/blog/api/blog/v1" |
||||
"github.com/go-kratos/kratos/examples/blog/internal/biz" |
||||
|
||||
"github.com/go-kratos/kratos/v2/log" |
||||
"github.com/google/wire" |
||||
) |
||||
|
||||
// ProviderSet is service providers.
|
||||
var ProviderSet = wire.NewSet(NewBlogService) |
||||
|
||||
type BlogService struct { |
||||
pb.UnimplementedBlogServiceServer |
||||
|
||||
log *log.Helper |
||||
|
||||
article *biz.ArticleUsecase |
||||
} |
@ -1,126 +0,0 @@ |
||||
# Generated with protoc-gen-openapi |
||||
# https://github.com/google/gnostic/tree/master/apps/protoc-gen-openapi |
||||
|
||||
openapi: 3.0.3 |
||||
info: |
||||
title: BlogService |
||||
version: 0.0.1 |
||||
paths: |
||||
/v1/article/: |
||||
get: |
||||
operationId: BlogService_ListArticle |
||||
responses: |
||||
"200": |
||||
description: OK |
||||
content: |
||||
application/json: |
||||
schema: |
||||
$ref: '#/components/schemas/ListArticleReply' |
||||
post: |
||||
operationId: BlogService_CreateArticle |
||||
requestBody: |
||||
content: |
||||
application/json: |
||||
schema: |
||||
$ref: '#/components/schemas/CreateArticleRequest' |
||||
required: true |
||||
responses: |
||||
"200": |
||||
description: OK |
||||
content: |
||||
application/json: |
||||
schema: |
||||
$ref: '#/components/schemas/CreateArticleReply' |
||||
/v1/article/{id}: |
||||
get: |
||||
operationId: BlogService_GetArticle |
||||
parameters: |
||||
- name: id |
||||
in: query |
||||
schema: |
||||
type: string |
||||
responses: |
||||
"200": |
||||
description: OK |
||||
content: |
||||
application/json: |
||||
schema: |
||||
$ref: '#/components/schemas/GetArticleReply' |
||||
put: |
||||
operationId: BlogService_UpdateArticle |
||||
requestBody: |
||||
content: |
||||
application/json: |
||||
schema: |
||||
$ref: '#/components/schemas/UpdateArticleRequest' |
||||
required: true |
||||
responses: |
||||
"200": |
||||
description: OK |
||||
content: |
||||
application/json: |
||||
schema: |
||||
$ref: '#/components/schemas/UpdateArticleReply' |
||||
delete: |
||||
operationId: BlogService_DeleteArticle |
||||
parameters: |
||||
- name: id |
||||
in: query |
||||
schema: |
||||
type: string |
||||
responses: |
||||
"200": |
||||
description: OK |
||||
content: |
||||
application/json: |
||||
schema: |
||||
$ref: '#/components/schemas/DeleteArticleReply' |
||||
components: |
||||
schemas: |
||||
Article: |
||||
properties: |
||||
id: |
||||
type: integer |
||||
format: int64 |
||||
title: |
||||
type: string |
||||
content: |
||||
type: string |
||||
like: |
||||
type: integer |
||||
format: int64 |
||||
CreateArticleReply: |
||||
properties: |
||||
Article: |
||||
$ref: '#/components/schemas/Article' |
||||
CreateArticleRequest: |
||||
properties: |
||||
title: |
||||
type: string |
||||
content: |
||||
type: string |
||||
DeleteArticleReply: |
||||
properties: {} |
||||
GetArticleReply: |
||||
properties: |
||||
Article: |
||||
$ref: '#/components/schemas/Article' |
||||
ListArticleReply: |
||||
properties: |
||||
results: |
||||
type: array |
||||
items: |
||||
$ref: '#/components/schemas/Article' |
||||
UpdateArticleReply: |
||||
properties: |
||||
Article: |
||||
$ref: '#/components/schemas/Article' |
||||
UpdateArticleRequest: |
||||
properties: |
||||
id: |
||||
type: integer |
||||
format: int64 |
||||
title: |
||||
type: string |
||||
content: |
||||
type: string |
@ -1,10 +0,0 @@ |
||||
### Profiles |
||||
examples/config/apollo is apollo config example. |
||||
You can deploy Apollo yourself or use docker compose in example to start Apollo, |
||||
then modify the configuration in the code to your actual Apollo configuration, |
||||
and run the program |
||||
|
||||
### Sample account |
||||
|
||||
Account: `apollo` |
||||
Password: `admin` |
@ -1,50 +0,0 @@ |
||||
# |
||||
# Copyright 2021 Apollo Authors |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
# |
||||
version: '2' |
||||
|
||||
services: |
||||
apollo-quick-start: |
||||
image: nobodyiam/apollo-quick-start |
||||
container_name: apollo-quick-start |
||||
depends_on: |
||||
- apollo-db |
||||
ports: |
||||
- "8080:8080" |
||||
- "8090:8090" |
||||
- "8070:8070" |
||||
links: |
||||
- apollo-db |
||||
|
||||
apollo-db: |
||||
image: mysql:5.7 |
||||
container_name: apollo-db |
||||
environment: |
||||
TZ: Asia/Shanghai |
||||
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' |
||||
depends_on: |
||||
- apollo-dbdata |
||||
ports: |
||||
- "13306:3306" |
||||
volumes: |
||||
- ./sql:/docker-entrypoint-initdb.d |
||||
volumes_from: |
||||
- apollo-dbdata |
||||
|
||||
apollo-dbdata: |
||||
image: alpine:latest |
||||
container_name: apollo-dbdata |
||||
volumes: |
||||
- /var/lib/mysql |
@ -1,448 +0,0 @@ |
||||
-- |
||||
-- Copyright 2021 Apollo Authors |
||||
-- |
||||
-- Licensed under the Apache License, Version 2.0 (the "License"); |
||||
-- you may not use this file except in compliance with the License. |
||||
-- You may obtain a copy of the License at |
||||
-- |
||||
-- http://www.apache.org/licenses/LICENSE-2.0 |
||||
-- |
||||
-- Unless required by applicable law or agreed to in writing, software |
||||
-- distributed under the License is distributed on an "AS IS" BASIS, |
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
-- See the License for the specific language governing permissions and |
||||
-- limitations under the License. |
||||
-- |
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; |
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; |
||||
/*!40101 SET NAMES utf8 */; |
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; |
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; |
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; |
||||
|
||||
# Create Database |
||||
# ------------------------------------------------------------ |
||||
CREATE DATABASE IF NOT EXISTS ApolloConfigDB DEFAULT CHARACTER SET = utf8mb4; |
||||
|
||||
Use ApolloConfigDB; |
||||
|
||||
# Dump of table app |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `App`; |
||||
|
||||
CREATE TABLE `App` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', |
||||
`AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', |
||||
`OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', |
||||
`OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', |
||||
`OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', |
||||
`OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `AppId` (`AppId`(191)), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_Name` (`Name`(191)) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; |
||||
|
||||
|
||||
|
||||
# Dump of table appnamespace |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `AppNamespace`; |
||||
|
||||
CREATE TABLE `AppNamespace` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', |
||||
`Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', |
||||
`AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', |
||||
`Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', |
||||
`IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', |
||||
`Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_AppId` (`AppId`), |
||||
KEY `Name_AppId` (`Name`,`AppId`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; |
||||
|
||||
|
||||
|
||||
# Dump of table audit |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Audit`; |
||||
|
||||
CREATE TABLE `Audit` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', |
||||
`EntityName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '表名', |
||||
`EntityId` int(10) unsigned DEFAULT NULL COMMENT '记录ID', |
||||
`OpName` varchar(50) NOT NULL DEFAULT 'default' COMMENT '操作类型', |
||||
`Comment` varchar(500) DEFAULT NULL COMMENT '备注', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='日志审计表'; |
||||
|
||||
|
||||
|
||||
# Dump of table cluster |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Cluster`; |
||||
|
||||
CREATE TABLE `Cluster` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', |
||||
`Name` varchar(32) NOT NULL DEFAULT '' COMMENT '集群名字', |
||||
`AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'App id', |
||||
`ParentClusterId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父cluster', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_AppId_Name` (`AppId`,`Name`), |
||||
KEY `IX_ParentClusterId` (`ParentClusterId`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='集群'; |
||||
|
||||
|
||||
|
||||
# Dump of table commit |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Commit`; |
||||
|
||||
CREATE TABLE `Commit` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', |
||||
`ChangeSets` longtext NOT NULL COMMENT '修改变更集', |
||||
`AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', |
||||
`NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', |
||||
`Comment` varchar(500) DEFAULT NULL COMMENT '备注', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `AppId` (`AppId`(191)), |
||||
KEY `ClusterName` (`ClusterName`(191)), |
||||
KEY `NamespaceName` (`NamespaceName`(191)) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='commit 历史表'; |
||||
|
||||
# Dump of table grayreleaserule |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `GrayReleaseRule`; |
||||
|
||||
CREATE TABLE `GrayReleaseRule` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', |
||||
`AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', |
||||
`NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', |
||||
`BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'branch name', |
||||
`Rules` varchar(16000) DEFAULT '[]' COMMENT '灰度规则', |
||||
`ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '灰度对应的release', |
||||
`BranchStatus` tinyint(2) DEFAULT '1' COMMENT '灰度分支状态: 0:删除分支,1:正在使用的规则 2:全量发布', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='灰度规则表'; |
||||
|
||||
|
||||
# Dump of table instance |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Instance`; |
||||
|
||||
CREATE TABLE `Instance` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', |
||||
`DataCenter` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Data Center Name', |
||||
`Ip` varchar(32) NOT NULL DEFAULT '' COMMENT 'instance ip', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
UNIQUE KEY `IX_UNIQUE_KEY` (`AppId`,`ClusterName`,`Ip`,`DataCenter`), |
||||
KEY `IX_IP` (`Ip`), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='使用配置的应用实例'; |
||||
|
||||
|
||||
|
||||
# Dump of table instanceconfig |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `InstanceConfig`; |
||||
|
||||
CREATE TABLE `InstanceConfig` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`InstanceId` int(11) unsigned DEFAULT NULL COMMENT 'Instance Id', |
||||
`ConfigAppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'Config App Id', |
||||
`ConfigClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Cluster Name', |
||||
`ConfigNamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'Config Namespace Name', |
||||
`ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', |
||||
`ReleaseDeliveryTime` timestamp NULL DEFAULT NULL COMMENT '配置获取时间', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
UNIQUE KEY `IX_UNIQUE_KEY` (`InstanceId`,`ConfigAppId`,`ConfigNamespaceName`), |
||||
KEY `IX_ReleaseKey` (`ReleaseKey`), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_Valid_Namespace` (`ConfigAppId`,`ConfigClusterName`,`ConfigNamespaceName`,`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用实例的配置信息'; |
||||
|
||||
|
||||
|
||||
# Dump of table item |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Item`; |
||||
|
||||
CREATE TABLE `Item` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', |
||||
`Key` varchar(128) NOT NULL DEFAULT 'default' COMMENT '配置项Key', |
||||
`Value` longtext NOT NULL COMMENT '配置项值', |
||||
`Comment` varchar(1024) DEFAULT '' COMMENT '注释', |
||||
`LineNum` int(10) unsigned DEFAULT '0' COMMENT '行号', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_GroupId` (`NamespaceId`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置项目'; |
||||
|
||||
|
||||
|
||||
# Dump of table namespace |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Namespace`; |
||||
|
||||
CREATE TABLE `Namespace` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', |
||||
`AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Cluster Name', |
||||
`NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'Namespace Name', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `AppId_ClusterName_NamespaceName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_NamespaceName` (`NamespaceName`(191)) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='命名空间'; |
||||
|
||||
|
||||
|
||||
# Dump of table namespacelock |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `NamespaceLock`; |
||||
|
||||
CREATE TABLE `NamespaceLock` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增id', |
||||
`NamespaceId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '集群NamespaceId', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
`IsDeleted` bit(1) DEFAULT b'0' COMMENT '软删除', |
||||
PRIMARY KEY (`Id`), |
||||
UNIQUE KEY `IX_NamespaceId` (`NamespaceId`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='namespace的编辑锁'; |
||||
|
||||
|
||||
|
||||
# Dump of table release |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Release`; |
||||
|
||||
CREATE TABLE `Release` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', |
||||
`ReleaseKey` varchar(64) NOT NULL DEFAULT '' COMMENT '发布的Key', |
||||
`Name` varchar(64) NOT NULL DEFAULT 'default' COMMENT '发布名字', |
||||
`Comment` varchar(256) DEFAULT NULL COMMENT '发布说明', |
||||
`AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`ClusterName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', |
||||
`NamespaceName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', |
||||
`Configurations` longtext NOT NULL COMMENT '发布配置', |
||||
`IsAbandoned` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否废弃', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `AppId_ClusterName_GroupName` (`AppId`(191),`ClusterName`(191),`NamespaceName`(191)), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_ReleaseKey` (`ReleaseKey`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布'; |
||||
|
||||
|
||||
# Dump of table releasehistory |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `ReleaseHistory`; |
||||
|
||||
CREATE TABLE `ReleaseHistory` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`AppId` varchar(64) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`ClusterName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'ClusterName', |
||||
`NamespaceName` varchar(32) NOT NULL DEFAULT 'default' COMMENT 'namespaceName', |
||||
`BranchName` varchar(32) NOT NULL DEFAULT 'default' COMMENT '发布分支名', |
||||
`ReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '关联的Release Id', |
||||
`PreviousReleaseId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '前一次发布的ReleaseId', |
||||
`Operation` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '发布类型,0: 普通发布,1: 回滚,2: 灰度发布,3: 灰度规则更新,4: 灰度合并回主分支发布,5: 主分支发布灰度自动发布,6: 主分支回滚灰度自动发布,7: 放弃灰度', |
||||
`OperationContext` longtext NOT NULL COMMENT '发布上下文信息', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_Namespace` (`AppId`,`ClusterName`,`NamespaceName`,`BranchName`), |
||||
KEY `IX_ReleaseId` (`ReleaseId`), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布历史'; |
||||
|
||||
|
||||
# Dump of table releasemessage |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `ReleaseMessage`; |
||||
|
||||
CREATE TABLE `ReleaseMessage` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', |
||||
`Message` varchar(1024) NOT NULL DEFAULT '' COMMENT '发布的消息内容', |
||||
`DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_Message` (`Message`(191)) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='发布消息'; |
||||
|
||||
|
||||
|
||||
# Dump of table serverconfig |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `ServerConfig`; |
||||
|
||||
CREATE TABLE `ServerConfig` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', |
||||
`Cluster` varchar(32) NOT NULL DEFAULT 'default' COMMENT '配置对应的集群,default为不针对特定的集群', |
||||
`Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', |
||||
`Comment` varchar(1024) DEFAULT '' COMMENT '注释', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_Key` (`Key`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; |
||||
|
||||
# Dump of table accesskey |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `AccessKey`; |
||||
|
||||
CREATE TABLE `AccessKey` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', |
||||
`AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`Secret` varchar(128) NOT NULL DEFAULT '' COMMENT 'Secret', |
||||
`IsEnabled` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: enabled, 0: disabled', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `AppId` (`AppId`(191)), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='访问密钥'; |
||||
|
||||
# Config |
||||
# ------------------------------------------------------------ |
||||
INSERT INTO `ServerConfig` (`Key`, `Cluster`, `Value`, `Comment`) |
||||
VALUES |
||||
('eureka.service.url', 'default', 'http://localhost:8080/eureka/', 'Eureka服务Url,多个service以英文逗号分隔'), |
||||
('namespace.lock.switch', 'default', 'false', '一次发布只能有一个人修改开关'), |
||||
('item.value.length.limit', 'default', '20000', 'item value最大长度限制'), |
||||
('config-service.cache.enabled', 'default', 'false', 'ConfigService是否开启缓存,开启后能提高性能,但是会增大内存消耗!'), |
||||
('item.key.length.limit', 'default', '128', 'item key 最大长度限制'); |
||||
|
||||
# Sample Data |
||||
# ------------------------------------------------------------ |
||||
INSERT INTO `App` (`AppId`, `Name`, `OrgId`, `OrgName`, `OwnerName`, `OwnerEmail`) |
||||
VALUES |
||||
('SampleApp', 'Sample App', 'TEST1', '样例部门1', 'apollo', 'apollo@acme.com'); |
||||
|
||||
INSERT INTO `AppNamespace` (`Name`, `AppId`, `Format`, `IsPublic`, `Comment`) |
||||
VALUES |
||||
('application', 'SampleApp', 'properties', 0, 'default app namespace'); |
||||
|
||||
INSERT INTO `Cluster` (`Name`, `AppId`) |
||||
VALUES |
||||
('default', 'SampleApp'); |
||||
|
||||
INSERT INTO `Namespace` (`Id`, `AppId`, `ClusterName`, `NamespaceName`) |
||||
VALUES |
||||
(1, 'SampleApp', 'default', 'application'); |
||||
|
||||
|
||||
INSERT INTO `Item` (`NamespaceId`, `Key`, `Value`, `Comment`, `LineNum`) |
||||
VALUES |
||||
(1, 'timeout', '100', 'sample timeout配置', 1); |
||||
|
||||
INSERT INTO `Release` (`ReleaseKey`, `Name`, `Comment`, `AppId`, `ClusterName`, `NamespaceName`, `Configurations`) |
||||
VALUES |
||||
('20161009155425-d3a0749c6e20bc15', '20161009155424-release', 'Sample发布', 'SampleApp', 'default', 'application', '{\"timeout\":\"100\"}'); |
||||
|
||||
INSERT INTO `ReleaseHistory` (`AppId`, `ClusterName`, `NamespaceName`, `BranchName`, `ReleaseId`, `PreviousReleaseId`, `Operation`, `OperationContext`, `DataChange_CreatedBy`, `DataChange_LastModifiedBy`) |
||||
VALUES |
||||
('SampleApp', 'default', 'application', 'default', 1, 0, 0, '{}', 'apollo', 'apollo'); |
||||
|
||||
INSERT INTO `ReleaseMessage` (`Message`) |
||||
VALUES |
||||
('SampleApp+default+application'); |
||||
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; |
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; |
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; |
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; |
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
@ -1,408 +0,0 @@ |
||||
-- |
||||
-- Copyright 2021 Apollo Authors |
||||
-- |
||||
-- Licensed under the Apache License, Version 2.0 (the "License"); |
||||
-- you may not use this file except in compliance with the License. |
||||
-- You may obtain a copy of the License at |
||||
-- |
||||
-- http://www.apache.org/licenses/LICENSE-2.0 |
||||
-- |
||||
-- Unless required by applicable law or agreed to in writing, software |
||||
-- distributed under the License is distributed on an "AS IS" BASIS, |
||||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
-- See the License for the specific language governing permissions and |
||||
-- limitations under the License. |
||||
-- |
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; |
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; |
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; |
||||
/*!40101 SET NAMES utf8 */; |
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; |
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; |
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; |
||||
|
||||
# Create Database |
||||
# ------------------------------------------------------------ |
||||
CREATE DATABASE IF NOT EXISTS ApolloPortalDB DEFAULT CHARACTER SET = utf8mb4; |
||||
|
||||
Use ApolloPortalDB; |
||||
|
||||
# Dump of table app |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `App`; |
||||
|
||||
CREATE TABLE `App` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', |
||||
`AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', |
||||
`OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', |
||||
`OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', |
||||
`OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', |
||||
`OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `AppId` (`AppId`(191)), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_Name` (`Name`(191)) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用表'; |
||||
|
||||
|
||||
|
||||
# Dump of table appnamespace |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `AppNamespace`; |
||||
|
||||
CREATE TABLE `AppNamespace` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', |
||||
`Name` varchar(32) NOT NULL DEFAULT '' COMMENT 'namespace名字,注意,需要全局唯一', |
||||
`AppId` varchar(64) NOT NULL DEFAULT '' COMMENT 'app id', |
||||
`Format` varchar(32) NOT NULL DEFAULT 'properties' COMMENT 'namespace的format类型', |
||||
`IsPublic` bit(1) NOT NULL DEFAULT b'0' COMMENT 'namespace是否为公共', |
||||
`Comment` varchar(64) NOT NULL DEFAULT '' COMMENT '注释', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_AppId` (`AppId`), |
||||
KEY `Name_AppId` (`Name`,`AppId`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用namespace定义'; |
||||
|
||||
|
||||
|
||||
# Dump of table consumer |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Consumer`; |
||||
|
||||
CREATE TABLE `Consumer` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`Name` varchar(500) NOT NULL DEFAULT 'default' COMMENT '应用名', |
||||
`OrgId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '部门Id', |
||||
`OrgName` varchar(64) NOT NULL DEFAULT 'default' COMMENT '部门名字', |
||||
`OwnerName` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerName', |
||||
`OwnerEmail` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'ownerEmail', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `AppId` (`AppId`(191)), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='开放API消费者'; |
||||
|
||||
|
||||
|
||||
# Dump of table consumeraudit |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `ConsumerAudit`; |
||||
|
||||
CREATE TABLE `ConsumerAudit` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', |
||||
`Uri` varchar(1024) NOT NULL DEFAULT '' COMMENT '访问的Uri', |
||||
`Method` varchar(16) NOT NULL DEFAULT '' COMMENT '访问的Method', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_ConsumerId` (`ConsumerId`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer审计表'; |
||||
|
||||
|
||||
|
||||
# Dump of table consumerrole |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `ConsumerRole`; |
||||
|
||||
CREATE TABLE `ConsumerRole` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'Consumer Id', |
||||
`RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_RoleId` (`RoleId`), |
||||
KEY `IX_ConsumerId_RoleId` (`ConsumerId`,`RoleId`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer和role的绑定表'; |
||||
|
||||
|
||||
|
||||
# Dump of table consumertoken |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `ConsumerToken`; |
||||
|
||||
CREATE TABLE `ConsumerToken` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`ConsumerId` int(11) unsigned DEFAULT NULL COMMENT 'ConsumerId', |
||||
`Token` varchar(128) NOT NULL DEFAULT '' COMMENT 'token', |
||||
`Expires` datetime NOT NULL DEFAULT '2099-01-01 00:00:00' COMMENT 'token失效时间', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
UNIQUE KEY `IX_Token` (`Token`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='consumer token表'; |
||||
|
||||
# Dump of table favorite |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Favorite`; |
||||
|
||||
CREATE TABLE `Favorite` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', |
||||
`UserId` varchar(32) NOT NULL DEFAULT 'default' COMMENT '收藏的用户', |
||||
`AppId` varchar(500) NOT NULL DEFAULT 'default' COMMENT 'AppID', |
||||
`Position` int(32) NOT NULL DEFAULT '10000' COMMENT '收藏顺序', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `AppId` (`AppId`(191)), |
||||
KEY `IX_UserId` (`UserId`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb4 COMMENT='应用收藏表'; |
||||
|
||||
# Dump of table permission |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Permission`; |
||||
|
||||
CREATE TABLE `Permission` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`PermissionType` varchar(32) NOT NULL DEFAULT '' COMMENT '权限类型', |
||||
`TargetId` varchar(256) NOT NULL DEFAULT '' COMMENT '权限对象类型', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_TargetId_PermissionType` (`TargetId`(191),`PermissionType`), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='permission表'; |
||||
|
||||
|
||||
|
||||
# Dump of table role |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Role`; |
||||
|
||||
CREATE TABLE `Role` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`RoleName` varchar(256) NOT NULL DEFAULT '' COMMENT 'Role name', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_RoleName` (`RoleName`(191)), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; |
||||
|
||||
|
||||
|
||||
# Dump of table rolepermission |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `RolePermission`; |
||||
|
||||
CREATE TABLE `RolePermission` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', |
||||
`PermissionId` int(10) unsigned DEFAULT NULL COMMENT 'Permission Id', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_RoleId` (`RoleId`), |
||||
KEY `IX_PermissionId` (`PermissionId`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='角色和权限的绑定表'; |
||||
|
||||
|
||||
|
||||
# Dump of table serverconfig |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `ServerConfig`; |
||||
|
||||
CREATE TABLE `ServerConfig` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`Key` varchar(64) NOT NULL DEFAULT 'default' COMMENT '配置项Key', |
||||
`Value` varchar(2048) NOT NULL DEFAULT 'default' COMMENT '配置项值', |
||||
`Comment` varchar(1024) DEFAULT '' COMMENT '注释', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_Key` (`Key`), |
||||
KEY `DataChange_LastTime` (`DataChange_LastTime`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配置服务自身配置'; |
||||
|
||||
|
||||
|
||||
# Dump of table userrole |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `UserRole`; |
||||
|
||||
CREATE TABLE `UserRole` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`UserId` varchar(128) DEFAULT '' COMMENT '用户身份标识', |
||||
`RoleId` int(10) unsigned DEFAULT NULL COMMENT 'Role Id', |
||||
`IsDeleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '1: deleted, 0: normal', |
||||
`DataChange_CreatedBy` varchar(64) NOT NULL DEFAULT 'default' COMMENT '创建人邮箱前缀', |
||||
`DataChange_CreatedTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
||||
`DataChange_LastModifiedBy` varchar(64) DEFAULT '' COMMENT '最后修改人邮箱前缀', |
||||
`DataChange_LastTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间', |
||||
PRIMARY KEY (`Id`), |
||||
KEY `IX_DataChange_LastTime` (`DataChange_LastTime`), |
||||
KEY `IX_RoleId` (`RoleId`), |
||||
KEY `IX_UserId_RoleId` (`UserId`,`RoleId`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户和role的绑定表'; |
||||
|
||||
# Dump of table Users |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Users`; |
||||
|
||||
CREATE TABLE `Users` ( |
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`Username` varchar(64) NOT NULL DEFAULT 'default' COMMENT '用户登录账户', |
||||
`Password` varchar(512) NOT NULL DEFAULT 'default' COMMENT '密码', |
||||
`UserDisplayName` varchar(512) NOT NULL DEFAULT 'default' COMMENT '用户名称', |
||||
`Email` varchar(64) NOT NULL DEFAULT 'default' COMMENT '邮箱地址', |
||||
`Enabled` tinyint(4) DEFAULT NULL COMMENT '是否有效', |
||||
PRIMARY KEY (`Id`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; |
||||
|
||||
|
||||
# Dump of table Authorities |
||||
# ------------------------------------------------------------ |
||||
|
||||
DROP TABLE IF EXISTS `Authorities`; |
||||
|
||||
CREATE TABLE `Authorities` ( |
||||
`Id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增Id', |
||||
`Username` varchar(64) NOT NULL, |
||||
`Authority` varchar(50) NOT NULL, |
||||
PRIMARY KEY (`Id`) |
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
||||
|
||||
|
||||
# Config |
||||
# ------------------------------------------------------------ |
||||
INSERT INTO `ServerConfig` (`Key`, `Value`, `Comment`) |
||||
VALUES |
||||
('apollo.portal.envs', 'dev', '可支持的环境列表'), |
||||
('organizations', '[{\"orgId\":\"TEST1\",\"orgName\":\"样例部门1\"},{\"orgId\":\"TEST2\",\"orgName\":\"样例部门2\"}]', '部门列表'), |
||||
('superAdmin', 'apollo', 'Portal超级管理员'), |
||||
('api.readTimeout', '10000', 'http接口read timeout'), |
||||
('consumer.token.salt', 'someSalt', 'consumer token salt'), |
||||
('admin.createPrivateNamespace.switch', 'true', '是否允许项目管理员创建私有namespace'), |
||||
('configView.memberOnly.envs', 'dev', '只对项目成员显示配置信息的环境列表,多个env以英文逗号分隔'), |
||||
('apollo.portal.meta.servers', '{}', '各环境Meta Service列表'); |
||||
|
||||
INSERT INTO `Users` (`Username`, `Password`, `UserDisplayName`, `Email`, `Enabled`) |
||||
VALUES |
||||
('apollo', '$2a$10$7r20uS.BQ9uBpf3Baj3uQOZvMVvB1RN3PYoKE94gtz2.WAOuiiwXS', 'apollo', 'apollo@acme.com', 1); |
||||
|
||||
INSERT INTO `Authorities` (`Username`, `Authority`) VALUES ('apollo', 'ROLE_user'); |
||||
|
||||
# Sample Data |
||||
# ------------------------------------------------------------ |
||||
INSERT INTO `App` (`AppId`, `Name`, `OrgId`, `OrgName`, `OwnerName`, `OwnerEmail`) |
||||
VALUES |
||||
('SampleApp', 'Sample App', 'TEST1', '样例部门1', 'apollo', 'apollo@acme.com'); |
||||
|
||||
INSERT INTO `AppNamespace` (`Name`, `AppId`, `Format`, `IsPublic`, `Comment`) |
||||
VALUES |
||||
('application', 'SampleApp', 'properties', 0, 'default app namespace'); |
||||
|
||||
INSERT INTO `Permission` (`Id`, `PermissionType`, `TargetId`) |
||||
VALUES |
||||
(1, 'CreateCluster', 'SampleApp'), |
||||
(2, 'CreateNamespace', 'SampleApp'), |
||||
(3, 'AssignRole', 'SampleApp'), |
||||
(4, 'ModifyNamespace', 'SampleApp+application'), |
||||
(5, 'ReleaseNamespace', 'SampleApp+application'); |
||||
|
||||
INSERT INTO `Role` (`Id`, `RoleName`) |
||||
VALUES |
||||
(1, 'Master+SampleApp'), |
||||
(2, 'ModifyNamespace+SampleApp+application'), |
||||
(3, 'ReleaseNamespace+SampleApp+application'); |
||||
|
||||
INSERT INTO `RolePermission` (`RoleId`, `PermissionId`) |
||||
VALUES |
||||
(1, 1), |
||||
(1, 2), |
||||
(1, 3), |
||||
(2, 4), |
||||
(3, 5); |
||||
|
||||
INSERT INTO `UserRole` (`UserId`, `RoleId`) |
||||
VALUES |
||||
('apollo', 1), |
||||
('apollo', 2), |
||||
('apollo', 3); |
||||
|
||||
-- spring session (https://github.com/spring-projects/spring-session/blob/faee8f1bdb8822a5653a81eba838dddf224d92d6/spring-session-jdbc/src/main/resources/org/springframework/session/jdbc/schema-mysql.sql) |
||||
CREATE TABLE SPRING_SESSION ( |
||||
PRIMARY_ID CHAR(36) NOT NULL, |
||||
SESSION_ID CHAR(36) NOT NULL, |
||||
CREATION_TIME BIGINT NOT NULL, |
||||
LAST_ACCESS_TIME BIGINT NOT NULL, |
||||
MAX_INACTIVE_INTERVAL INT NOT NULL, |
||||
EXPIRY_TIME BIGINT NOT NULL, |
||||
PRINCIPAL_NAME VARCHAR(100), |
||||
CONSTRAINT SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID) |
||||
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; |
||||
|
||||
CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID); |
||||
CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME); |
||||
CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME); |
||||
|
||||
CREATE TABLE SPRING_SESSION_ATTRIBUTES ( |
||||
SESSION_PRIMARY_ID CHAR(36) NOT NULL, |
||||
ATTRIBUTE_NAME VARCHAR(200) NOT NULL, |
||||
ATTRIBUTE_BYTES BLOB NOT NULL, |
||||
CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME), |
||||
CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) REFERENCES SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE |
||||
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; |
||||
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; |
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; |
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; |
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; |
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; |
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
@ -1,81 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"log" |
||||
|
||||
_ "github.com/go-kratos/kratos/v2/encoding/json" |
||||
_ "github.com/go-kratos/kratos/v2/encoding/yaml" |
||||
|
||||
"github.com/go-kratos/kratos/contrib/config/apollo/v2" |
||||
"github.com/go-kratos/kratos/v2/config" |
||||
) |
||||
|
||||
type bootstrap struct { |
||||
Application struct { |
||||
Name string `json:"name"` |
||||
Version string `json:"version"` |
||||
} `json:"application"` |
||||
|
||||
Event struct { |
||||
Key string `json:"key"` |
||||
Array []string `json:"array"` |
||||
} `json:"event"` |
||||
|
||||
Demo struct { |
||||
Deep struct { |
||||
Key string `json:"key"` |
||||
Value string `json:"value"` |
||||
} `json:"deep"` |
||||
} `json:"demo"` |
||||
} |
||||
|
||||
func main() { |
||||
c := config.New( |
||||
config.WithSource( |
||||
apollo.NewSource( |
||||
apollo.WithAppID("kratos"), |
||||
apollo.WithCluster("dev"), |
||||
apollo.WithEndpoint("http://localhost:8080"), |
||||
apollo.WithNamespace("application,event.yaml,demo.json"), |
||||
apollo.WithEnableBackup(), |
||||
apollo.WithSecret("ad75b33c77ae4b9c9626d969c44f41ee"), |
||||
), |
||||
), |
||||
) |
||||
var bc bootstrap |
||||
if err := c.Load(); err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
scan(c, &bc) |
||||
|
||||
value(c, "application") |
||||
value(c, "application.name") |
||||
value(c, "event.array") |
||||
value(c, "demo.deep") |
||||
|
||||
watch(c, "application") |
||||
<-make(chan struct{}) |
||||
} |
||||
|
||||
func scan(c config.Config, bc *bootstrap) { |
||||
err := c.Scan(bc) |
||||
fmt.Printf("=========== scan result =============\n") |
||||
fmt.Printf("err: %v\n", err) |
||||
fmt.Printf("cfg: %+v\n\n", bc) |
||||
} |
||||
|
||||
func value(c config.Config, key string) { |
||||
fmt.Printf("=========== value result =============\n") |
||||
v := c.Value(key).Load() |
||||
fmt.Printf("key=%s, load: %+v\n\n", key, v) |
||||
} |
||||
|
||||
func watch(c config.Config, key string) { |
||||
if err := c.Watch(key, func(key string, value config.Value) { |
||||
log.Printf("config(key=%s) changed: %s\n", key, value.Load()) |
||||
}); err != nil { |
||||
panic(err) |
||||
} |
||||
} |
@ -1,11 +0,0 @@ |
||||
service: |
||||
name: config |
||||
version: v1.0.0 |
||||
http: |
||||
server: |
||||
address: 0.0.0.0:8000 |
||||
timeout: 1s |
||||
grpc: |
||||
server: |
||||
address: 0.0.0.0:9000 |
||||
timeout: 1s |
@ -1,57 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"flag" |
||||
"log" |
||||
|
||||
"github.com/go-kratos/kratos/v2/config" |
||||
"github.com/go-kratos/kratos/v2/config/file" |
||||
) |
||||
|
||||
var flagconf string |
||||
|
||||
func init() { |
||||
flag.StringVar(&flagconf, "conf", "config.yaml", "config path, eg: -conf config.yaml") |
||||
} |
||||
|
||||
func main() { |
||||
flag.Parse() |
||||
c := config.New( |
||||
config.WithSource( |
||||
file.NewSource(flagconf), |
||||
), |
||||
) |
||||
if err := c.Load(); err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
// Defines the config JSON Field
|
||||
var v struct { |
||||
Service struct { |
||||
Name string `json:"name"` |
||||
Version string `json:"version"` |
||||
} `json:"service"` |
||||
} |
||||
|
||||
// Unmarshal the config to struct
|
||||
if err := c.Scan(&v); err != nil { |
||||
panic(err) |
||||
} |
||||
log.Printf("config: %+v", v) |
||||
|
||||
// Get a value associated with the key
|
||||
name, err := c.Value("service.name").String() |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
log.Printf("service: %s", name) |
||||
|
||||
// watch key
|
||||
if err := c.Watch("service.name", func(key string, value config.Value) { |
||||
log.Printf("config changed: %s = %v\n", key, value) |
||||
}); err != nil { |
||||
panic(err) |
||||
} |
||||
|
||||
<-make(chan struct{}) |
||||
} |
@ -1,5 +0,0 @@ |
||||
foo: |
||||
baz: "2" |
||||
biu: "example" |
||||
hello: |
||||
a: b |
@ -1,6 +0,0 @@ |
||||
foo: |
||||
bar: 3 |
||||
baz: aaaa |
||||
hey: |
||||
good: bad |
||||
qux: quux |
@ -1,136 +0,0 @@ |
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.26.0
|
||||
// protoc v3.17.1
|
||||
// source: error_reason.proto
|
||||
|
||||
package api |
||||
|
||||
import ( |
||||
_ "github.com/go-kratos/kratos/v2/errors" |
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect" |
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl" |
||||
reflect "reflect" |
||||
sync "sync" |
||||
) |
||||
|
||||
const ( |
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) |
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) |
||||
) |
||||
|
||||
type ErrorReason int32 |
||||
|
||||
const ( |
||||
ErrorReason_USER_NOT_FOUND ErrorReason = 0 |
||||
ErrorReason_CONTENT_MISSING ErrorReason = 1 |
||||
) |
||||
|
||||
// Enum value maps for ErrorReason.
|
||||
var ( |
||||
ErrorReason_name = map[int32]string{ |
||||
0: "USER_NOT_FOUND", |
||||
1: "CONTENT_MISSING", |
||||
} |
||||
ErrorReason_value = map[string]int32{ |
||||
"USER_NOT_FOUND": 0, |
||||
"CONTENT_MISSING": 1, |
||||
} |
||||
) |
||||
|
||||
func (x ErrorReason) Enum() *ErrorReason { |
||||
p := new(ErrorReason) |
||||
*p = x |
||||
return p |
||||
} |
||||
|
||||
func (x ErrorReason) String() string { |
||||
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) |
||||
} |
||||
|
||||
func (ErrorReason) Descriptor() protoreflect.EnumDescriptor { |
||||
return file_error_reason_proto_enumTypes[0].Descriptor() |
||||
} |
||||
|
||||
func (ErrorReason) Type() protoreflect.EnumType { |
||||
return &file_error_reason_proto_enumTypes[0] |
||||
} |
||||
|
||||
func (x ErrorReason) Number() protoreflect.EnumNumber { |
||||
return protoreflect.EnumNumber(x) |
||||
} |
||||
|
||||
// Deprecated: Use ErrorReason.Descriptor instead.
|
||||
func (ErrorReason) EnumDescriptor() ([]byte, []int) { |
||||
return file_error_reason_proto_rawDescGZIP(), []int{0} |
||||
} |
||||
|
||||
var File_error_reason_proto protoreflect.FileDescriptor |
||||
|
||||
var file_error_reason_proto_rawDesc = []byte{ |
||||
0x0a, 0x12, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x2e, 0x70, |
||||
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x1a, 0x0c, 0x65, 0x72, |
||||
0x72, 0x6f, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2a, 0x48, 0x0a, 0x0b, 0x45, 0x72, |
||||
0x72, 0x6f, 0x72, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x0e, 0x55, 0x53, 0x45, |
||||
0x52, 0x5f, 0x4e, 0x4f, 0x54, 0x5f, 0x46, 0x4f, 0x55, 0x4e, 0x44, 0x10, 0x00, 0x1a, 0x04, 0xa8, |
||||
0x45, 0x94, 0x03, 0x12, 0x19, 0x0a, 0x0f, 0x43, 0x4f, 0x4e, 0x54, 0x45, 0x4e, 0x54, 0x5f, 0x4d, |
||||
0x49, 0x53, 0x53, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x1a, 0x04, 0xa8, 0x45, 0x90, 0x03, 0x1a, 0x04, |
||||
0xa0, 0x45, 0xf4, 0x03, 0x42, 0x57, 0x0a, 0x0e, 0x62, 0x6c, 0x6f, 0x67, 0x2e, 0x76, 0x31, 0x2e, |
||||
0x65, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x50, 0x01, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, |
||||
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f, 0x2d, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x6b, |
||||
0x72, 0x61, 0x74, 0x6f, 0x73, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x62, |
||||
0x6c, 0x6f, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0xa2, 0x02, 0x0d, |
||||
0x41, 0x50, 0x49, 0x42, 0x6c, 0x6f, 0x67, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x73, 0x62, 0x06, 0x70, |
||||
0x72, 0x6f, 0x74, 0x6f, 0x33, |
||||
} |
||||
|
||||
var ( |
||||
file_error_reason_proto_rawDescOnce sync.Once |
||||
file_error_reason_proto_rawDescData = file_error_reason_proto_rawDesc |
||||
) |
||||
|
||||
func file_error_reason_proto_rawDescGZIP() []byte { |
||||
file_error_reason_proto_rawDescOnce.Do(func() { |
||||
file_error_reason_proto_rawDescData = protoimpl.X.CompressGZIP(file_error_reason_proto_rawDescData) |
||||
}) |
||||
return file_error_reason_proto_rawDescData |
||||
} |
||||
|
||||
var file_error_reason_proto_enumTypes = make([]protoimpl.EnumInfo, 1) |
||||
var file_error_reason_proto_goTypes = []interface{}{ |
||||
(ErrorReason)(0), // 0: errors.ErrorReason
|
||||
} |
||||
var file_error_reason_proto_depIdxs = []int32{ |
||||
0, // [0:0] is the sub-list for method output_type
|
||||
0, // [0:0] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
} |
||||
|
||||
func init() { file_error_reason_proto_init() } |
||||
func file_error_reason_proto_init() { |
||||
if File_error_reason_proto != nil { |
||||
return |
||||
} |
||||
type x struct{} |
||||
out := protoimpl.TypeBuilder{ |
||||
File: protoimpl.DescBuilder{ |
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), |
||||
RawDescriptor: file_error_reason_proto_rawDesc, |
||||
NumEnums: 1, |
||||
NumMessages: 0, |
||||
NumExtensions: 0, |
||||
NumServices: 0, |
||||
}, |
||||
GoTypes: file_error_reason_proto_goTypes, |
||||
DependencyIndexes: file_error_reason_proto_depIdxs, |
||||
EnumInfos: file_error_reason_proto_enumTypes, |
||||
}.Build() |
||||
File_error_reason_proto = out.File |
||||
file_error_reason_proto_rawDesc = nil |
||||
file_error_reason_proto_goTypes = nil |
||||
file_error_reason_proto_depIdxs = nil |
||||
} |
@ -1,18 +0,0 @@ |
||||
syntax = "proto3"; |
||||
|
||||
package errors; |
||||
|
||||
import "errors/errors.proto"; |
||||
|
||||
// 多语言特定包名,用于源代码引用 |
||||
option go_package = "github.com/go-kratos/kratos/examples/blog/api/v1;v1"; |
||||
option java_multiple_files = true; |
||||
option java_package = "blog.v1.errors"; |
||||
option objc_class_prefix = "APIBlogErrors"; |
||||
|
||||
enum ErrorReason { |
||||
option (errors.default_code) = 500; |
||||
|
||||
USER_NOT_FOUND = 0 [(errors.code) = 404]; |
||||
CONTENT_MISSING = 1 [(errors.code) = 400];; |
||||
} |
@ -1,30 +0,0 @@ |
||||
// Code generated by protoc-gen-go-errors. DO NOT EDIT.
|
||||
|
||||
package api |
||||
|
||||
import ( |
||||
fmt "fmt" |
||||
errors "github.com/go-kratos/kratos/v2/errors" |
||||
) |
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the kratos package it is being compiled against.
|
||||
const _ = errors.SupportPackageIsVersion1 |
||||
|
||||
func IsUserNotFound(err error) bool { |
||||
e := errors.FromError(err) |
||||
return e.Reason == ErrorReason_USER_NOT_FOUND.String() && e.Code == 404 |
||||
} |
||||
|
||||
func ErrorUserNotFound(format string, args ...interface{}) *errors.Error { |
||||
return errors.New(404, ErrorReason_USER_NOT_FOUND.String(), fmt.Sprintf(format, args...)) |
||||
} |
||||
|
||||
func IsContentMissing(err error) bool { |
||||
e := errors.FromError(err) |
||||
return e.Reason == ErrorReason_CONTENT_MISSING.String() && e.Code == 400 |
||||
} |
||||
|
||||
func ErrorContentMissing(format string, args ...interface{}) *errors.Error { |
||||
return errors.New(400, ErrorReason_CONTENT_MISSING.String(), fmt.Sprintf(format, args...)) |
||||
} |
@ -1,64 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"context" |
||||
"log" |
||||
|
||||
stdhttp "net/http" |
||||
|
||||
"github.com/go-kratos/kratos/examples/errors/api" |
||||
pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" |
||||
"github.com/go-kratos/kratos/v2/errors" |
||||
"github.com/go-kratos/kratos/v2/transport/grpc" |
||||
"github.com/go-kratos/kratos/v2/transport/http" |
||||
) |
||||
|
||||
func main() { |
||||
callHTTP() |
||||
callGRPC() |
||||
} |
||||
|
||||
func callHTTP() { |
||||
conn, err := http.NewClient( |
||||
context.Background(), |
||||
http.WithEndpoint("127.0.0.1:8000"), |
||||
) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
client := pb.NewGreeterHTTPClient(conn) |
||||
reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "empty"}) |
||||
if err != nil { |
||||
if errors.Code(err) == stdhttp.StatusInternalServerError { |
||||
log.Println(err) |
||||
} |
||||
if api.IsUserNotFound(err) { |
||||
log.Println("[http] USER_NOT_FOUND_ERROR", err) |
||||
} |
||||
} else { |
||||
log.Printf("[http] SayHello %s\n", reply.Message) |
||||
} |
||||
} |
||||
|
||||
func callGRPC() { |
||||
conn, err := grpc.DialInsecure( |
||||
context.Background(), |
||||
grpc.WithEndpoint("127.0.0.1:9000"), |
||||
) |
||||
if err != nil { |
||||
panic(err) |
||||
} |
||||
client := pb.NewGreeterClient(conn) |
||||
reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) |
||||
if err != nil { |
||||
e := errors.FromError(err) |
||||
if e.Reason == "USER_NAME_EMPTY" && e.Code == 500 { |
||||
log.Println("[grpc] USER_NAME_EMPTY", err) |
||||
} |
||||
if api.IsUserNotFound(err) { |
||||
log.Println("[grpc] USER_NOT_FOUND_ERROR", err) |
||||
} |
||||
} else { |
||||
log.Printf("[grpc] SayHello %+v\n", reply) |
||||
} |
||||
} |
@ -1,65 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"log" |
||||
|
||||
"github.com/go-kratos/kratos/examples/errors/api" |
||||
"github.com/go-kratos/kratos/examples/helloworld/helloworld" |
||||
"github.com/go-kratos/kratos/v2" |
||||
"github.com/go-kratos/kratos/v2/errors" |
||||
"github.com/go-kratos/kratos/v2/transport/grpc" |
||||
"github.com/go-kratos/kratos/v2/transport/http" |
||||
) |
||||
|
||||
// go build -ldflags "-X main.Version=x.y.z"
|
||||
var ( |
||||
// Name is the name of the compiled software.
|
||||
Name = "errors" |
||||
// Version is the version of the compiled software.
|
||||
// Version = "v1.0.0"
|
||||
) |
||||
|
||||
// server is used to implement helloworld.GreeterServer.
|
||||
type server struct { |
||||
helloworld.UnimplementedGreeterServer |
||||
} |
||||
|
||||
// SayHello implements helloworld.GreeterServer
|
||||
func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { |
||||
fmt.Println(in.Name) |
||||
if in.Name == "empty" { |
||||
// Respond to errors through errors.New().
|
||||
return nil, errors.New(500, "USER_NAME_EMPTY", "user name is empty") |
||||
} |
||||
if in.Name == "kratos" { |
||||
// Respond to errors with proto generated code.
|
||||
return nil, api.ErrorUserNotFound("user %s not found", "kratos") |
||||
} |
||||
return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %+v", in.Name)}, nil |
||||
} |
||||
|
||||
func main() { |
||||
s := &server{} |
||||
grpcSrv := grpc.NewServer( |
||||
grpc.Address(":9000"), |
||||
) |
||||
httpSrv := http.NewServer( |
||||
http.Address(":8000"), |
||||
) |
||||
helloworld.RegisterGreeterServer(grpcSrv, s) |
||||
helloworld.RegisterGreeterHTTPServer(httpSrv, s) |
||||
|
||||
app := kratos.New( |
||||
kratos.Name(Name), |
||||
kratos.Server( |
||||
httpSrv, |
||||
grpcSrv, |
||||
), |
||||
) |
||||
|
||||
if err := app.Run(); err != nil { |
||||
log.Fatal(err) |
||||
} |
||||
} |
@ -1,20 +0,0 @@ |
||||
package event |
||||
|
||||
import "context" |
||||
|
||||
type Event interface { |
||||
Key() string |
||||
Value() []byte |
||||
} |
||||
|
||||
type Handler func(context.Context, Event) error |
||||
|
||||
type Sender interface { |
||||
Send(ctx context.Context, msg Event) error |
||||
Close() error |
||||
} |
||||
|
||||
type Receiver interface { |
||||
Receive(ctx context.Context, handler Handler) error |
||||
Close() error |
||||
} |
@ -1,114 +0,0 @@ |
||||
package kafka |
||||
|
||||
import ( |
||||
"context" |
||||
"log" |
||||
|
||||
"github.com/go-kratos/kratos/examples/event/event" |
||||
"github.com/segmentio/kafka-go" |
||||
) |
||||
|
||||
var ( |
||||
_ event.Sender = (*kafkaSender)(nil) |
||||
_ event.Receiver = (*kafkaReceiver)(nil) |
||||
_ event.Event = (*Message)(nil) |
||||
) |
||||
|
||||
type Message struct { |
||||
key string |
||||
value []byte |
||||
} |
||||
|
||||
func (m *Message) Key() string { |
||||
return m.key |
||||
} |
||||
|
||||
func (m *Message) Value() []byte { |
||||
return m.value |
||||
} |
||||
|
||||
func NewMessage(key string, value []byte) event.Event { |
||||
return &Message{ |
||||
key: key, |
||||
value: value, |
||||
} |
||||
} |
||||
|
||||
type kafkaSender struct { |
||||
writer *kafka.Writer |
||||
topic string |
||||
} |
||||
|
||||
func (s *kafkaSender) Send(ctx context.Context, message event.Event) error { |
||||
err := s.writer.WriteMessages(ctx, kafka.Message{ |
||||
Key: []byte(message.Key()), |
||||
Value: message.Value(), |
||||
}) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (s *kafkaSender) Close() error { |
||||
err := s.writer.Close() |
||||
if err != nil { |
||||
return err |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func NewKafkaSender(address []string, topic string) (event.Sender, error) { |
||||
w := &kafka.Writer{ |
||||
Topic: topic, |
||||
Addr: kafka.TCP(address...), |
||||
Balancer: &kafka.LeastBytes{}, |
||||
} |
||||
return &kafkaSender{writer: w, topic: topic}, nil |
||||
} |
||||
|
||||
type kafkaReceiver struct { |
||||
reader *kafka.Reader |
||||
topic string |
||||
} |
||||
|
||||
func (k *kafkaReceiver) Receive(ctx context.Context, handler event.Handler) error { |
||||
go func() { |
||||
for { |
||||
m, err := k.reader.FetchMessage(context.Background()) |
||||
if err != nil { |
||||
break |
||||
} |
||||
err = handler(context.Background(), &Message{ |
||||
key: string(m.Key), |
||||
value: m.Value, |
||||
}) |
||||
if err != nil { |
||||
log.Fatal("message handling exception:", err) |
||||
} |
||||
if err := k.reader.CommitMessages(ctx, m); err != nil { |
||||
log.Fatal("failed to commit messages:", err) |
||||
} |
||||
} |
||||
}() |
||||
return nil |
||||
} |
||||
|
||||
func (k *kafkaReceiver) Close() error { |
||||
err := k.reader.Close() |
||||
if err != nil { |
||||
return err |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func NewKafkaReceiver(address []string, topic string) (event.Receiver, error) { |
||||
r := kafka.NewReader(kafka.ReaderConfig{ |
||||
Brokers: address, |
||||
GroupID: "group-a", |
||||
Topic: topic, |
||||
MinBytes: 10e3, // 10KB
|
||||
MaxBytes: 10e6, // 10MB
|
||||
}) |
||||
return &kafkaReceiver{reader: r, topic: topic}, nil |
||||
} |
@ -1,88 +0,0 @@ |
||||
package memory |
||||
|
||||
import ( |
||||
"context" |
||||
"log" |
||||
"sync" |
||||
|
||||
"github.com/go-kratos/kratos/examples/event/event" |
||||
) |
||||
|
||||
var ( |
||||
_ event.Sender = (*memorySender)(nil) |
||||
_ event.Receiver = (*memoryReceiver)(nil) |
||||
_ event.Event = (*Message)(nil) |
||||
) |
||||
|
||||
var ( |
||||
chanMap = struct { |
||||
sync.RWMutex |
||||
cm map[string]chan *Message |
||||
}{} |
||||
ChanSize = 256 |
||||
) |
||||
|
||||
func init() { |
||||
chanMap.cm = make(map[string]chan *Message) |
||||
} |
||||
|
||||
type Message struct { |
||||
key string |
||||
value []byte |
||||
} |
||||
|
||||
func (m *Message) Key() string { |
||||
return m.key |
||||
} |
||||
|
||||
func (m *Message) Value() []byte { |
||||
return m.value |
||||
} |
||||
|
||||
type memorySender struct { |
||||
topic string |
||||
} |
||||
|
||||
func (m *memorySender) Send(ctx context.Context, msg event.Event) error { |
||||
chanMap.cm[m.topic] <- &Message{ |
||||
key: msg.Key(), |
||||
value: msg.Value(), |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (m *memorySender) Close() error { |
||||
return nil |
||||
} |
||||
|
||||
type memoryReceiver struct { |
||||
topic string |
||||
} |
||||
|
||||
func (m *memoryReceiver) Receive(ctx context.Context, handler event.Handler) error { |
||||
go func() { |
||||
for msg := range chanMap.cm[m.topic] { |
||||
err := handler(context.Background(), msg) |
||||
if err != nil { |
||||
log.Fatal("message handling exception:", err) |
||||
} |
||||
} |
||||
}() |
||||
return nil |
||||
} |
||||
|
||||
func (m *memoryReceiver) Close() error { |
||||
return nil |
||||
} |
||||
|
||||
func NewMemory(topic string) (event.Sender, event.Receiver) { |
||||
chanMap.RLock() |
||||
if _, ok := chanMap.cm[topic]; !ok { |
||||
// chanMap.Lock()
|
||||
chanMap.cm[topic] = make(chan *Message, ChanSize) |
||||
// chanMap.Unlock()
|
||||
} |
||||
defer chanMap.RUnlock() |
||||
|
||||
return &memorySender{topic: topic}, &memoryReceiver{topic: topic} |
||||
} |
@ -1,33 +0,0 @@ |
||||
package memory |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"testing" |
||||
"time" |
||||
|
||||
"github.com/go-kratos/kratos/examples/event/event" |
||||
) |
||||
|
||||
func TestSendAndReceive(t *testing.T) { |
||||
send, receive := NewMemory("test") |
||||
err := receive.Receive(context.Background(), func(ctx context.Context, event event.Event) error { |
||||
t.Log(fmt.Sprintf("key:%s, value:%s\n", event.Key(), event.Value())) |
||||
return nil |
||||
}) |
||||
if err != nil { |
||||
t.Error(err) |
||||
} |
||||
|
||||
for i := 0; i < 5; i++ { |
||||
err := send.Send(context.Background(), &Message{ |
||||
key: "kratos", |
||||
value: []byte("hello world"), |
||||
}) |
||||
if err != nil { |
||||
t.Error(err) |
||||
} |
||||
} |
||||
|
||||
time.Sleep(5 * time.Second) |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue