Browse Source

init

master
dark 1 year ago
commit
e42ce84f99
  1. 66
      apifile/teThoroughlyRegister.api
  2. 39
      demo.api
  3. BIN
      demo.exe
  4. 31
      demo.go
  5. 11
      etc/demo-api.yaml
  6. 59
      go.mod
  7. 147
      go.sum
  8. 15
      internal/config/config.go
  9. 28
      internal/handler/demohandler.go
  10. 21
      internal/handler/esbusinesspressuretesthandler.go
  11. 28
      internal/handler/espressuretesthandler.go
  12. 21
      internal/handler/pinghandler.go
  13. 42
      internal/handler/routes.go
  14. 28
      internal/handler/testinghandler.go
  15. 30
      internal/logic/demologic.go
  16. 30
      internal/logic/esbusinesspressuretestlogic.go
  17. 54
      internal/logic/espressuretestlogic.go
  18. 32
      internal/logic/pinglogic.go
  19. 55
      internal/logic/testinglogic.go
  20. 22
      internal/svc/servicecontext.go
  21. 72
      internal/types/types.go
  22. 139
      model/es/esmodel.go
  23. 24
      model/tethoroughlyregistermodel.go
  24. 142
      model/tethoroughlyregistermodel_gen.go
  25. 5
      model/vars.go
  26. 6
      readme.md

66
apifile/teThoroughlyRegister.api

@ -0,0 +1,66 @@
syntax = "v1"
type TestRequest {
// Id string `json:"id"`
PlanId string `json:"plan_id"`
Name string `json:"name"`
Sex string `json:"sex"`
CardType string `json:"card_type"`
IdCard string `json:"id_card"`
IdCardSensitive string `json:"id_card_sensitive"`
Birthday int64 `json:"birthday"`
Nation string `json:"nation,optional"`
Country string `json:"country,optional"`
State int64 `json:"state,optional"`
RegisteredResidence string `json:"registered_residence,optional"`
DistrictCode string `json:"district_code,optional"`
District string `json:"district,optional"`
StudentType string `json:"student_type,optional"`
Address string `json:"address,optional"`
RegisteredType string `json:"registered_type,optional"`
NoHouse string `json:"no_house,optional"`
FamilyStatus string `json:"family_status,optional"`
Year int64 `json:"year,optional"`
RegisterCode string `json:"register_code,optional"`
AccountId string `json:"account_id,optional"`
HouseType string `json:"house_type,optional"`
NativePlace string `json:"native_place,optional"`
Kindergarten string `json:"kindergarten,optional"`
SchoolId string `json:"school_id,optional"`
SchoolName string `json:"school_name,optional"`
HighwayId string `json:"highway_id,,optional"`
RoadNumberId string `json:"road_number_id,optional"`
BloodType string `json:"blood_type,optional"`
OnlyChild bool `json:"only_child,optional"`
BirthPlace string `json:"birth_place,optional"`
HealthCondition string `json:"health_condition,optional"`
Speciality string `json:"speciality,optional"`
FillSource string `json:"fill_source,optional"`
AreaId string `json:"area_id,optional"`
SingleParent bool `json:"single_parent,optional"`
HighwayName string `json:"highway_name,optional"`
RoadNumberName string `json:"road_number_name,optional"`
GuardianPermit1 int64 `json:"guardian_permit1,optional"`
GuardianPermit2 int64 `json:"guardian_permit2,optional"`
IdCardFile string `json:"id_card_file,optional"`
FillPhone string `json:"fill_phone,optional"`
LocationOther bool `json:"location_other,optional"`
CityHouse bool `json:"city_house,optional"`
IsWuming bool `json:"is_wuming,optional"`
}
// 通用api返回参数
type TestResponse {
Success bool `json:"success,default=true"` // 是否成功
Message string `json:"message,optional"` // 消息
Result interface{} `json:"data,optional"` // 数据
Total int64 `json:"total,optional"` // 总数
}
service demo-api {
@doc(
summary: "测试接口",
)
@handler TestingHandler
post /testing (TestRequest) returns (TestResponse)
}

39
demo.api

@ -0,0 +1,39 @@
syntax = "v1"
import "/apifile/teThoroughlyRegister.api"
type Request {
Name string `path:"name,options=you|me"`
}
type EsQueryName {
Name string `json:"name"`
}
// 通用api返回参数
type Response {
Success bool `json:"success,default=true"` // 是否成功
Message string `json:"message,optional"` // 消息
Result interface{} `json:"data,optional"` // 数据
Total int64 `json:"total,optional"` // 总数
}
service demo-api {
@doc(
summary: "获取系统状态",
)
@handler PingHandler
post /ping returns (Response)
@doc(
summary: "es 压测 demo",
)
@handler EsPressureTestHandler
post /es/pressureTest(EsQueryName) returns (Response)
@doc(
summary: "es 业务压测 demo",
)
@handler EsBusinessPressureTestHandler
post /es/businessPressureTest returns (Response)
}

BIN
demo.exe

Binary file not shown.

31
demo.go

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

11
etc/demo-api.yaml

@ -0,0 +1,11 @@
Name: demo-api
Host: 0.0.0.0
Port: 8888
Pg:
# postgresql 连接配置
DataSource: postgres://postgres:123456@127.0.0.1:/postgres?sslmode=disable
CacheRedis:
- Host: 127.0.0.1:6379
# Pass: $pass
Type: node

59
go.mod

@ -0,0 +1,59 @@
module demo
go 1.19
require (
github.com/elastic/go-elasticsearch/v7 v7.17.10
github.com/google/uuid v1.6.0
github.com/jinzhu/copier v0.4.0
github.com/json-iterator/go v1.1.12
github.com/lib/pq v1.10.9
github.com/zeromicro/go-zero v1.6.3
)
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/redis/go-redis/v9 v9.4.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

147
go.sum

@ -0,0 +1,147 @@
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
github.com/alicebob/miniredis/v2 v2.31.1 h1:7XAt0uUg3DtwEKW5ZAGa+K7FZV2DdKQo5K/6TTnfX8Y=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/elastic/go-elasticsearch/v7 v7.17.10 h1:TCQ8i4PmIJuBunvBS6bwT2ybzVFxxUhhltAs3Gyu1yo=
github.com/elastic/go-elasticsearch/v7 v7.17.10/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA=
github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM=
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/redis/go-redis/v9 v9.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk=
github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE=
github.com/zeromicro/go-zero v1.6.3 h1:OL0NnHD5LdRNDolfcK9vUkJt7K8TcBE3RkzfM8poOVw=
github.com/zeromicro/go-zero v1.6.3/go.mod h1:XZL435ZxVi9MSXXtw2MRQhHgx6OoX3++MRMOE9xU70c=
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 h1:D7UpUy2Xc2wsi1Ras6V40q806WM07rqoCWzXu7Sqy+4=
go.opentelemetry.io/otel/exporters/jaeger v1.17.0/go.mod h1:nPCqOnEH9rNLKqH/+rrUjiMzHJdV1BlpKcTwRTyKkKI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 h1:Mne5On7VWdx7omSrSSZvM4Kw7cS7NQkOOmLcgscI51U=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0/go.mod h1:IPtUMKL4O3tH5y+iXVyAXqpAwMuzC1IrxVS81rummfE=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 h1:3d+S281UTjM+AbF31XSOYn1qXn3BgIdWl8HNEpx08Jk=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0/go.mod h1:0+KuTDyKL4gjKCF75pHOX4wuzYDUZYfAQdSu43o+Z2I=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 h1:Nw7Dv4lwvGrI68+wULbcq7su9K2cebeCUrDjVrUJHxM=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0/go.mod h1:1MsF6Y7gTqosgoZvHlzcaaM8DIMNZgJh87ykokoNH7Y=
go.opentelemetry.io/otel/exporters/zipkin v1.19.0 h1:EGY0h5mGliP9o/nIkVuLI0vRiQqmsYOcbwCuotksO1o=
go.opentelemetry.io/otel/exporters/zipkin v1.19.0/go.mod h1:JQgTGJP11yi3o4GHzIWYodhPisxANdqxF1eHwDSnJrI=
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o=
go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A=
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
go.opentelemetry.io/proto/otlp v1.0.0 h1:T0TX0tmXU8a3CbNXzEKGeU5mIVOdf0oykP+u2lIVU/I=
go.opentelemetry.io/proto/otlp v1.0.0/go.mod h1:Sy6pihPLfYHkr3NkUbEhGHFhINUSI/v80hjKIs5JXpM=
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 h1:Lj5rbfG876hIAYFjqiJnPHfhXbv+nzTWfm04Fg/XSVU=
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.62.0 h1:HQKZ/fa1bXkX1oFOvSjmZEUL8wLSaZTjCcLAlmZRtdk=
google.golang.org/grpc v1.62.0/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=

15
internal/config/config.go

@ -0,0 +1,15 @@
package config
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/rest"
)
type Config struct {
rest.RestConf
Pg struct {
DataSource string
}
CacheRedis cache.CacheConf
}

28
internal/handler/demohandler.go

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

21
internal/handler/esbusinesspressuretesthandler.go

@ -0,0 +1,21 @@
package handler
import (
"net/http"
"demo/internal/logic"
"demo/internal/svc"
"github.com/zeromicro/go-zero/rest/httpx"
)
func EsBusinessPressureTestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := logic.NewEsBusinessPressureTestLogic(r.Context(), svcCtx)
resp, err := l.EsBusinessPressureTest()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

28
internal/handler/espressuretesthandler.go

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

21
internal/handler/pinghandler.go

@ -0,0 +1,21 @@
package handler
import (
"net/http"
"demo/internal/logic"
"demo/internal/svc"
"github.com/zeromicro/go-zero/rest/httpx"
)
func PingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := logic.NewPingLogic(r.Context(), svcCtx)
resp, err := l.Ping()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

42
internal/handler/routes.go

@ -0,0 +1,42 @@
// Code generated by goctl. DO NOT EDIT.
package handler
import (
"net/http"
"demo/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/ping",
Handler: PingHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/es/pressureTest",
Handler: EsPressureTestHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/es/businessPressureTest",
Handler: EsBusinessPressureTestHandler(serverCtx),
},
},
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/testing",
Handler: TestingHandler(serverCtx),
},
},
)
}

28
internal/handler/testinghandler.go

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

30
internal/logic/demologic.go

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

30
internal/logic/esbusinesspressuretestlogic.go

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

54
internal/logic/espressuretestlogic.go

@ -0,0 +1,54 @@
package logic
import (
"context"
"fmt"
"demo/internal/svc"
"demo/internal/types"
"demo/model/es"
"github.com/zeromicro/go-zero/core/logx"
)
type EsPressureTestLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewEsPressureTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EsPressureTestLogic {
return &EsPressureTestLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *EsPressureTestLogic) EsPressureTest(req *types.EsQueryName) (resp *types.Response, err error) {
// todo: add your logic here and delete this line
// todo: add your logic here and delete this line
esQuery := `
{
"query": {
"match_phrase": {
"districtName": "%s"
}
}
}
`
esQueryStr := fmt.Sprintf(esQuery, req.Name)
doc, err := es.EsServiceApp.EsSearchDocWithStr(l.ctx, esQueryStr, 0, 100)
if err != nil {
return nil, err
}
return &types.Response{
Success: true,
Message: "success",
Result: doc,
}, nil
}

32
internal/logic/pinglogic.go

@ -0,0 +1,32 @@
package logic
import (
"context"
"demo/internal/svc"
"demo/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type PingLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
return &PingLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PingLogic) Ping() (resp *types.Response, err error) {
// todo: add your logic here and delete this line
return &types.Response{
Message: "Pong",
}, nil
}

55
internal/logic/testinglogic.go

@ -0,0 +1,55 @@
package logic
import (
"context"
"time"
"demo/internal/svc"
"demo/internal/types"
teThoroughlyRegisterModel "demo/model"
"github.com/google/uuid"
"github.com/jinzhu/copier"
"github.com/zeromicro/go-zero/core/logx"
)
type TestingLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewTestingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestingLogic {
return &TestingLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *TestingLogic) Testing(req *types.TestRequest) (resp *types.TestResponse, err error) {
// 拷贝赋值
insData := new(teThoroughlyRegisterModel.TeThoroughlyRegister)
copier.Copy(insData, req)
// 额外赋值
insData.Id = uuid.New().String()
timeUnix := time.Now()
insData.CreatedAt = timeUnix
insData.UpdatedAt = timeUnix
insData.DeleteAt = 0
insData.CreatedBy = "admin"
insData.UpdatedBy = "admin"
// 插入数据
_, err = l.svcCtx.DbModel.Insert(l.ctx, insData)
if err != nil {
// 返回错误
return nil, err
}
// 返回数据
return &types.TestResponse{
Message: "success",
Success: true,
Result: insData,
}, nil
}

22
internal/svc/servicecontext.go

@ -0,0 +1,22 @@
package svc
import (
"demo/internal/config"
dbModel "demo/model"
_ "github.com/lib/pq"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
type ServiceContext struct {
Config config.Config
DbModel dbModel.TeThoroughlyRegisterModel
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := sqlx.NewSqlConn("postgres", c.Pg.DataSource)
return &ServiceContext{
Config: c,
DbModel: dbModel.NewTeThoroughlyRegisterModel(conn),
}
}

72
internal/types/types.go

@ -0,0 +1,72 @@
// Code generated by goctl. DO NOT EDIT.
package types
type Request struct {
Name string `path:"name,options=you|me"`
}
type EsQueryName struct {
Name string `json:"name"`
}
type Response struct {
Success bool `json:"success,default=true"` // 是否成功
Message string `json:"message,optional"` // 消息
Result interface{} `json:"data,optional"` // 数据
Total int64 `json:"total,optional"` // 总数
}
type TestRequest struct {
PlanId string `json:"plan_id"`
Name string `json:"name"`
Sex string `json:"sex"`
CardType string `json:"card_type"`
IdCard string `json:"id_card"`
IdCardSensitive string `json:"id_card_sensitive"`
Birthday int64 `json:"birthday"`
Nation string `json:"nation,optional"`
Country string `json:"country,optional"`
State int64 `json:"state,optional"`
RegisteredResidence string `json:"registered_residence,optional"`
DistrictCode string `json:"district_code,optional"`
District string `json:"district,optional"`
StudentType string `json:"student_type,optional"`
Address string `json:"address,optional"`
RegisteredType string `json:"registered_type,optional"`
NoHouse string `json:"no_house,optional"`
FamilyStatus string `json:"family_status,optional"`
Year int64 `json:"year,optional"`
RegisterCode string `json:"register_code,optional"`
AccountId string `json:"account_id,optional"`
HouseType string `json:"house_type,optional"`
NativePlace string `json:"native_place,optional"`
Kindergarten string `json:"kindergarten,optional"`
SchoolId string `json:"school_id,optional"`
SchoolName string `json:"school_name,optional"`
HighwayId string `json:"highway_id,,optional"`
RoadNumberId string `json:"road_number_id,optional"`
BloodType string `json:"blood_type,optional"`
OnlyChild bool `json:"only_child,optional"`
BirthPlace string `json:"birth_place,optional"`
HealthCondition string `json:"health_condition,optional"`
Speciality string `json:"speciality,optional"`
FillSource string `json:"fill_source,optional"`
AreaId string `json:"area_id,optional"`
SingleParent bool `json:"single_parent,optional"`
HighwayName string `json:"highway_name,optional"`
RoadNumberName string `json:"road_number_name,optional"`
GuardianPermit1 int64 `json:"guardian_permit1,optional"`
GuardianPermit2 int64 `json:"guardian_permit2,optional"`
IdCardFile string `json:"id_card_file,optional"`
FillPhone string `json:"fill_phone,optional"`
LocationOther bool `json:"location_other,optional"`
CityHouse bool `json:"city_house,optional"`
IsWuming bool `json:"is_wuming,optional"`
}
type TestResponse struct {
Success bool `json:"success,default=true"` // 是否成功
Message string `json:"message,optional"` // 消息
Result interface{} `json:"data,optional"` // 数据
Total int64 `json:"total,optional"` // 总数
}

139
model/es/esmodel.go

@ -0,0 +1,139 @@
package es
import (
"bytes"
"context"
"encoding/json"
esclient "github.com/elastic/go-elasticsearch/v7"
jsoniter "github.com/json-iterator/go"
)
type (
defaultEsService interface {
EsConnect() *esclient.Client
EsCreateIndex()
EsDeleteIndex()
EsAddDoc()
EsDeleteDoc()
EsUpdateDoc()
EsSearchDoc(index string, query map[string]interface{}, from int, size int) interface{}
}
EsService struct {
}
)
var (
EsServiceApp = new(EsService)
logIndex = "thoroughly_districts_xw"
)
func (e *EsService) EsConnect() *esclient.Client {
cfg := esclient.Config{
Addresses: []string{
"http://10.1.1.124:9200",
},
}
es, err := esclient.NewClient(cfg)
if err != nil {
panic(err)
}
return es
}
// 创建索引
func (e *EsService) EsCreateIndex() {
}
// 删除索引
func (e *EsService) EsDeleteIndex() {
}
// 添加文档
func (e *EsService) EsAddDoc() {
}
// 删除文档
func (e *EsService) EsDeleteDoc() {
}
// 更新文档
func (e *EsService) EsUpdateDoc() {
}
// 查询文档- map[string]interface{}
func (e *EsService) EsSearchDoc(ctx context.Context, query map[string]interface{}, from int, size int) (doc interface{}, err error) {
es := e.EsConnect()
// Build the request body.
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(query); err != nil {
// httpresult.ErrorResult("参数解析错误", err)
return nil, err
}
// Perform the search request.
res, err := es.Search(
es.Search.WithContext(context.Background()),
es.Search.WithIndex(logIndex),
es.Search.WithBody(&buf),
es.Search.WithTrackTotalHits(true),
es.Search.WithPretty(),
es.Search.WithFrom(from),
es.Search.WithSize(size),
// es.Search.WithSort("@timestamp:desc"),
)
if err != nil {
// httpresult.ErrorResult("查询失败", err)
return nil, err
}
defer res.Body.Close()
result := map[string]interface{}{}
jserr := jsoniter.NewDecoder(res.Body).Decode(&result)
if jserr != nil {
return nil, jserr
}
return result, nil
}
// 查询文档- muti string
func (e *EsService) EsSearchDocWithStr(ctx context.Context, query string, from int, size int) (doc interface{}, err error) {
es := e.EsConnect()
// Build the request body.
// var buf bytes.Buffer
// if err := json.NewEncoder(&buf).Encode(query); err != nil {
// httpresult.ErrorResult("参数解析错误", err)
// }
// Perform the search request.
// string query to io.Reader
// query = `{"query":{"match_all":{}}}`
var buf = bytes.NewBufferString(query)
res, err := es.Search(
es.Search.WithContext(context.Background()),
es.Search.WithIndex(logIndex),
es.Search.WithBody(buf),
es.Search.WithTrackTotalHits(true),
es.Search.WithPretty(),
es.Search.WithFrom(from),
es.Search.WithSize(size),
// es.Search.WithSort("@timestamp:desc"),
)
if err != nil {
// httpresult.ErrorResult("查询失败", err)
return nil, err
}
defer res.Body.Close()
result := map[string]interface{}{}
jserr := jsoniter.NewDecoder(res.Body).Decode(&result)
if jserr != nil {
return nil, jserr
}
return result, nil
}

24
model/tethoroughlyregistermodel.go

@ -0,0 +1,24 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ TeThoroughlyRegisterModel = (*customTeThoroughlyRegisterModel)(nil)
type (
// TeThoroughlyRegisterModel is an interface to be customized, add more methods here,
// and implement the added methods in customTeThoroughlyRegisterModel.
TeThoroughlyRegisterModel interface {
teThoroughlyRegisterModel
}
customTeThoroughlyRegisterModel struct {
*defaultTeThoroughlyRegisterModel
}
)
// NewTeThoroughlyRegisterModel returns a model for the database table.
func NewTeThoroughlyRegisterModel(conn sqlx.SqlConn) TeThoroughlyRegisterModel {
return &customTeThoroughlyRegisterModel{
defaultTeThoroughlyRegisterModel: newTeThoroughlyRegisterModel(conn),
}
}

142
model/tethoroughlyregistermodel_gen.go

@ -0,0 +1,142 @@
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
teThoroughlyRegisterFieldNames = builder.RawFieldNames(&TeThoroughlyRegister{}, true)
teThoroughlyRegisterRows = strings.Join(teThoroughlyRegisterFieldNames, ",")
teThoroughlyRegisterRowsExpectAutoSet = strings.Join(stringx.Remove(teThoroughlyRegisterFieldNames), ",")
teThoroughlyRegisterRowsWithPlaceHolder = builder.PostgreSqlJoin(stringx.Remove(teThoroughlyRegisterFieldNames, "id"))
)
type (
teThoroughlyRegisterModel interface {
Insert(ctx context.Context, data *TeThoroughlyRegister) (sql.Result, error)
FindOne(ctx context.Context, id string) (*TeThoroughlyRegister, error)
Update(ctx context.Context, data *TeThoroughlyRegister) error
Delete(ctx context.Context, id string) error
}
defaultTeThoroughlyRegisterModel struct {
conn sqlx.SqlConn
table string
}
TeThoroughlyRegister struct {
Id string `db:"id"`
PlanId string `db:"plan_id"`
Name string `db:"name"`
Sex string `db:"sex"`
CardType string `db:"card_type"`
IdCard string `db:"id_card"`
IdCardSensitive string `db:"id_card_sensitive"`
Birthday time.Time `db:"birthday"`
Nation string `db:"nation"`
Country string `db:"country"`
State int64 `db:"state"`
RegisteredResidence string `db:"registered_residence"`
DistrictCode string `db:"district_code"`
District string `db:"district"`
StudentType string `db:"student_type"`
Address string `db:"address"`
RegisteredType string `db:"registered_type"`
NoHouse string `db:"no_house"`
FamilyStatus string `db:"family_status"`
Year int64 `db:"year"`
RegisterCode string `db:"register_code"`
CreatedBy string `db:"created_by"`
CreatedAt time.Time `db:"created_at"`
UpdatedBy string `db:"updated_by"`
UpdatedAt time.Time `db:"updated_at"`
Deleted bool `db:"deleted"`
AccountId string `db:"account_id"`
HouseType string `db:"house_type"`
NativePlace string `db:"native_place"`
Kindergarten string `db:"kindergarten"`
SchoolId string `db:"school_id"`
SchoolName string `db:"school_name"`
HighwayId string `db:"highway_id"`
RoadNumberId string `db:"road_number_id"`
BloodType string `db:"blood_type"`
OnlyChild bool `db:"only_child"`
BirthPlace string `db:"birth_place"`
HealthCondition string `db:"health_condition"`
Speciality string `db:"speciality"`
FillSource string `db:"fill_source"`
AreaId string `db:"area_id"`
SingleParent bool `db:"single_parent"`
HighwayName string `db:"highway_name"`
RoadNumberName string `db:"road_number_name"`
GuardianPermit1 int64 `db:"guardian_permit1"`
GuardianPermit2 int64 `db:"guardian_permit2"`
IdCardFile string `db:"id_card_file"`
FillPhone string `db:"fill_phone"`
LocationOther bool `db:"location_other"`
CityHouse bool `db:"city_house"`
IsWuming bool `db:"is_wuming"`
DeleteAt int64 `db:"delete_at"`
}
)
func newTeThoroughlyRegisterModel(conn sqlx.SqlConn) *defaultTeThoroughlyRegisterModel {
return &defaultTeThoroughlyRegisterModel{
conn: conn,
table: `"public"."te_thoroughly_register"`,
}
}
func (m *defaultTeThoroughlyRegisterModel) withSession(session sqlx.Session) *defaultTeThoroughlyRegisterModel {
return &defaultTeThoroughlyRegisterModel{
conn: sqlx.NewSqlConnFromSession(session),
table: `"public"."te_thoroughly_register"`,
}
}
func (m *defaultTeThoroughlyRegisterModel) Delete(ctx context.Context, id string) error {
query := fmt.Sprintf("delete from %s where id = $1", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultTeThoroughlyRegisterModel) FindOne(ctx context.Context, id string) (*TeThoroughlyRegister, error) {
query := fmt.Sprintf("select %s from %s where id = $1 limit 1", teThoroughlyRegisterRows, m.table)
var resp TeThoroughlyRegister
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultTeThoroughlyRegisterModel) Insert(ctx context.Context, data *TeThoroughlyRegister) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, $51, $52)", m.table, teThoroughlyRegisterRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.PlanId, data.Name, data.Sex, data.CardType, data.IdCard, data.IdCardSensitive, data.Birthday, data.Nation, data.Country, data.State, data.RegisteredResidence, data.DistrictCode, data.District, data.StudentType, data.Address, data.RegisteredType, data.NoHouse, data.FamilyStatus, data.Year, data.RegisterCode, data.CreatedBy, data.CreatedAt, data.UpdatedBy, data.UpdatedAt, data.Deleted, data.AccountId, data.HouseType, data.NativePlace, data.Kindergarten, data.SchoolId, data.SchoolName, data.HighwayId, data.RoadNumberId, data.BloodType, data.OnlyChild, data.BirthPlace, data.HealthCondition, data.Speciality, data.FillSource, data.AreaId, data.SingleParent, data.HighwayName, data.RoadNumberName, data.GuardianPermit1, data.GuardianPermit2, data.IdCardFile, data.FillPhone, data.LocationOther, data.CityHouse, data.IsWuming, data.DeleteAt)
return ret, err
}
func (m *defaultTeThoroughlyRegisterModel) Update(ctx context.Context, data *TeThoroughlyRegister) error {
query := fmt.Sprintf("update %s set %s where id = $1", m.table, teThoroughlyRegisterRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Id, data.PlanId, data.Name, data.Sex, data.CardType, data.IdCard, data.IdCardSensitive, data.Birthday, data.Nation, data.Country, data.State, data.RegisteredResidence, data.DistrictCode, data.District, data.StudentType, data.Address, data.RegisteredType, data.NoHouse, data.FamilyStatus, data.Year, data.RegisterCode, data.CreatedBy, data.CreatedAt, data.UpdatedBy, data.UpdatedAt, data.Deleted, data.AccountId, data.HouseType, data.NativePlace, data.Kindergarten, data.SchoolId, data.SchoolName, data.HighwayId, data.RoadNumberId, data.BloodType, data.OnlyChild, data.BirthPlace, data.HealthCondition, data.Speciality, data.FillSource, data.AreaId, data.SingleParent, data.HighwayName, data.RoadNumberName, data.GuardianPermit1, data.GuardianPermit2, data.IdCardFile, data.FillPhone, data.LocationOther, data.CityHouse, data.IsWuming, data.DeleteAt)
return err
}
func (m *defaultTeThoroughlyRegisterModel) tableName() string {
return m.table
}

5
model/vars.go

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

6
readme.md

@ -0,0 +1,6 @@
# 生产model
goctl model pg datasource --url="postgres://postgres:123456@10.0.1.36:5432/postgres?sslmode=disable" --table="te_thoroughly_register" -dir ./model
# 本机
goctl model pg datasource --url="postgres://postgres:123456@127.0.0.1:5432/postgres?sslmode=disable" --table="te_thoroughly_register" -dir ./model
# api 生成
goctl api go -api demo.api -dir .
Loading…
Cancel
Save