Yi hace 1 año
padre
commit
6b6a190572

+ 2 - 1
cmd/http.go

@@ -5,7 +5,8 @@ import (
 	"kpt-event/config"
 	"kpt-event/dep"
 	"kpt-event/http"
-	log "kpt-event/util/logger"
+
+	log "gitee.com/xuyiping_admin/pkg/logger"
 
 	"github.com/spf13/cobra"
 )

+ 3 - 2
config/app.go

@@ -1,11 +1,12 @@
 package config
 
 import (
-	"kpt-event/util/di"
-	log "kpt-event/util/logger"
 	"os"
 	"strings"
 	"sync"
+
+	"gitee.com/xuyiping_admin/pkg/di"
+	log "gitee.com/xuyiping_admin/pkg/logger"
 )
 
 const AppName = "kptEvent"

+ 2 - 1
dep/dep.go

@@ -2,7 +2,8 @@ package dep
 
 import (
 	"kpt-event/config"
-	"kpt-event/util/di"
+
+	"gitee.com/xuyiping_admin/pkg/di"
 )
 
 // Global 全局所有的依赖

+ 1 - 1
dep/di.go

@@ -1,6 +1,6 @@
 package dep
 
-import "kpt-event/util/di"
+import "gitee.com/xuyiping_admin/pkg/di"
 
 func DI(opts ...di.HubOption) *di.Hub {
 	var hubOpts []di.HubOption

+ 20 - 24
go.mod

@@ -3,57 +3,53 @@ module kpt-event
 go 1.17
 
 require (
-	github.com/getsentry/sentry-go v0.15.0
+	github.com/getsentry/sentry-go v0.23.0
 	github.com/gin-contrib/cors v1.4.0
 	github.com/gin-contrib/gzip v0.0.6
 	github.com/gin-contrib/requestid v0.0.6
-	github.com/gin-gonic/gin v1.8.1
+	github.com/gin-gonic/gin v1.9.0
 	github.com/google/go-cmp v0.5.9
 	github.com/jinzhu/copier v0.3.5
 	github.com/mitchellh/mapstructure v1.5.0
-	github.com/sirupsen/logrus v1.9.0
+	github.com/sirupsen/logrus v1.9.3
 	github.com/spf13/cobra v1.6.1
 	github.com/spf13/viper v1.14.0
-	github.com/stretchr/testify v1.8.1
-	go.uber.org/dig v1.15.0
+	github.com/stretchr/testify v1.8.4
+	go.uber.org/dig v1.17.0
 )
 
 require (
+	gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584 // indirect
 	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/fsnotify/fsnotify v1.6.0 // indirect
 	github.com/gin-contrib/sse v0.1.0 // indirect
-	github.com/go-playground/locales v0.14.0 // indirect
-	github.com/go-playground/universal-translator v0.18.0 // indirect
-	github.com/go-playground/validator/v10 v10.11.1 // indirect
-	github.com/goccy/go-json v0.9.11 // indirect
-	github.com/golang/glog v1.0.0 // indirect
-	github.com/golang/protobuf v1.5.2 // indirect
+	github.com/go-playground/locales v0.14.1 // indirect
+	github.com/go-playground/universal-translator v0.18.1 // indirect
+	github.com/go-playground/validator/v10 v10.14.0 // indirect
+	github.com/goccy/go-json v0.10.2 // indirect
 	github.com/google/uuid v1.3.0 // indirect
-	github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
 	github.com/inconshreveable/mousetrap v1.0.1 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
-	github.com/leodido/go-urn v1.2.1 // indirect
-	github.com/magiconair/properties v1.8.6 // indirect
-	github.com/mattn/go-isatty v0.0.16 // indirect
+	github.com/leodido/go-urn v1.2.4 // indirect
+	github.com/magiconair/properties v1.8.7 // indirect
+	github.com/mattn/go-isatty v0.0.19 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/pelletier/go-toml v1.9.5 // indirect
-	github.com/pelletier/go-toml/v2 v2.0.5 // indirect
+	github.com/pelletier/go-toml/v2 v2.0.8 // indirect
 	github.com/pmezard/go-difflib v1.0.0 // indirect
 	github.com/spf13/afero v1.9.2 // indirect
 	github.com/spf13/cast v1.5.0 // indirect
 	github.com/spf13/jwalterweatherman v1.1.0 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
 	github.com/subosito/gotenv v1.4.1 // indirect
-	github.com/ugorji/go/codec v1.2.7 // indirect
-	golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect
-	golang.org/x/net v0.2.0 // indirect
-	golang.org/x/sys v0.2.0 // indirect
-	golang.org/x/text v0.4.0 // indirect
-	google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1 // indirect
-	google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 // indirect
-	google.golang.org/protobuf v1.28.1 // indirect
+	github.com/ugorji/go/codec v1.2.11 // indirect
+	golang.org/x/crypto v0.9.0 // indirect
+	golang.org/x/net v0.10.0 // indirect
+	golang.org/x/sys v0.8.0 // indirect
+	golang.org/x/text v0.9.0 // indirect
+	google.golang.org/protobuf v1.31.0 // indirect
 	gopkg.in/ini.v1 v1.67.0 // indirect
 	gopkg.in/yaml.v2 v2.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect

+ 26 - 11
go.sum

@@ -182,6 +182,8 @@ cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuW
 cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0=
 cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M=
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
+gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584 h1:5RE5yrMMvnDITrnoX821mFl7dNYfsFA1osDobUV/TDo=
+gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584/go.mod h1:VQ7WztVDQRlXE1dUu/Yqo3ZdhKsfv7IGJtV+vqNqJVw=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
@@ -278,6 +280,7 @@ github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4
 github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
 github.com/getsentry/sentry-go v0.15.0 h1:CP9bmA7pralrVUedYZsmIHWpq/pBtXTSew7xvVpfLaA=
 github.com/getsentry/sentry-go v0.15.0/go.mod h1:RZPJKSw+adu8PBNygiri/A98FqVr2HtRckJk9XVxJ9I=
+github.com/getsentry/sentry-go v0.23.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
 github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
 github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g=
 github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs=
@@ -289,6 +292,7 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8=
 github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
+github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k=
 github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
 github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
 github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
@@ -306,11 +310,14 @@ github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBY
 github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
 github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
 github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
+github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
 github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
 github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
+github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
 github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
 github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
 github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
+github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
 github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
@@ -320,13 +327,12 @@ github.com/gobwas/ws v1.1.0/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL
 github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
 github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
+github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
 github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
 github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
-github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
-github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
 github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -356,7 +362,6 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
 github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
 github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
-github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
 github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
 github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
@@ -425,8 +430,6 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+
 github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
-github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0 h1:t7uX3JBHdVwAi3G7sSSdbsk8NfgA+LnUS88V/2EKaA0=
-github.com/grpc-ecosystem/grpc-gateway/v2 v2.14.0/go.mod h1:4OGVnY4qf2+gw+ssiHbW+pq4mo2yko94YxxMmXZ7jCA=
 github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
 github.com/hashicorp/consul/api v1.15.3/go.mod h1:/g/qgcoBcEXALCNZgRRisyTW0nY86++L0KbeAMXYCeY=
 github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
@@ -530,11 +533,13 @@ github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20L
 github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
 github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
 github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
+github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
 github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
 github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
 github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
 github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
 github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
+github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
 github.com/mailgun/raymond/v2 v2.0.46/go.mod h1:lsgvL50kgt1ylcFJYZiULi5fjPBkkhNfj4KA0W54Z18=
 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
 github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
@@ -553,6 +558,7 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
 github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
 github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
+github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
 github.com/mediocregopher/radix/v3 v3.8.0/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8=
 github.com/microcosm-cc/bluemonday v1.0.20/go.mod h1:yfBmMi8mxvaZut3Yytv+jTXRY8mxyjJ0/kQBTElld50=
@@ -613,6 +619,7 @@ github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko
 github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
 github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
 github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
+github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
 github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
 github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
 github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@@ -670,6 +677,7 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf
 github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
 github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
 github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
+github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
 github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
 github.com/smartystreets/assertions v1.13.0/go.mod h1:wDmR7qL282YbGsPy6H/yAsesrxfxaaSlJazyFLYVFx8=
@@ -715,6 +723,9 @@ github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
 github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
 github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
 github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
 github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
@@ -731,6 +742,7 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6
 github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
 github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
 github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
+github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
 github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
 github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
 github.com/valyala/fasthttp v1.40.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
@@ -774,6 +786,7 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
 go.uber.org/dig v1.15.0 h1:vq3YWr8zRj1eFGC7Gvf907hE0eRjPTZ1d3xHadD6liE=
 go.uber.org/dig v1.15.0/go.mod h1:pKHs0wMynzL6brANhB2hLMro+zalv1osARTviTcqHLM=
+go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU=
 go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
 go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
 go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
@@ -802,6 +815,7 @@ golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0
 golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be h1:fmw3UbQh+nxngCAHrDCCztao/kbYFnWjoqop8dHx05A=
 golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
+golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -900,10 +914,10 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
 golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
 golang.org/x/net v0.0.0-20220909164309-bea034e7d591/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
 golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
-golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU=
 golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
 golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
 golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
+golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1045,11 +1059,14 @@ golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
 golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
 golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -1061,6 +1078,7 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
 golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
+golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
 golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -1296,8 +1314,6 @@ google.golang.org/genproto v0.0.0-20221010155953-15ba04fc1c0e/go.mod h1:3526vdqw
 google.golang.org/genproto v0.0.0-20221014173430-6e2ab493f96b/go.mod h1:1vXfmgAz9N9Jx0QA82PqRVauvCz1SGSz739p0f183jM=
 google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz9N9Jx0QA82PqRVauvCz1SGSz739p0f183jM=
 google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e/go.mod h1:9qHF0xnpdSfF6knlcsnpzUu5y+rpwgbvsyGAZPBMg4s=
-google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1 h1:jCw9YRd2s40X9Vxi4zKsPRvSPlHWNqadVkpbMsCPzPQ=
-google.golang.org/genproto v0.0.0-20221114212237-e4508ebdbee1/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg=
 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
 google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
 google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
@@ -1335,8 +1351,6 @@ google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCD
 google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
 google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
 google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
-google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 h1:TLkBREm4nIsEcexnCjgQd5GQWaHcqMzwQV0TX9pq8S0=
-google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -1353,6 +1367,7 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
 google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
 google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
 google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
+google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

+ 3 - 2
http/api/default.go

@@ -3,10 +3,11 @@ package api
 import (
 	"compress/gzip"
 	"fmt"
-	"github.com/gin-gonic/gin"
 	"io/ioutil"
-	"kpt-event/util/xerr"
 	"net/http"
+
+	"gitee.com/xuyiping_admin/pkg/xerr"
+	"github.com/gin-gonic/gin"
 )
 
 func Health(c *gin.Context) {

+ 3 - 2
http/middleware/sentry.go

@@ -1,10 +1,11 @@
 package middleware
 
 import (
-	sentry2 "kpt-event/util/sentry"
-	"kpt-event/util/xerr"
 	"sync"
 
+	sentry2 "gitee.com/xuyiping_admin/pkg/sentry"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+
 	"github.com/getsentry/sentry-go"
 	sentrygin "github.com/getsentry/sentry-go/gin"
 	"github.com/gin-gonic/gin"

+ 4 - 3
main.go

@@ -6,11 +6,12 @@ package main
 
 import (
 	"kpt-event/cmd"
-	log "kpt-event/util/logger"
+
+	log "gitee.com/xuyiping_admin/pkg/logger"
 )
 
 func main() {
-	log.Info("kpe-event: is starting")
+	log.Info("kpt-server: is starting")
 	cmd.Execute()
-	log.Error("kpt-event: is shut down")
+	log.Error("kpt-server: is shut down")
 }

+ 59 - 0
store/kptstore/rw_store.go

@@ -0,0 +1,59 @@
+package kptstore
+
+import (
+	"kpt-tmr-group/config"
+	"time"
+
+	"gitee.com/xuyiping_admin/pkg/logger/logrus"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+
+	"gorm.io/driver/mysql"
+	"gorm.io/gorm"
+	"gorm.io/gorm/logger"
+
+	"gitee.com/xuyiping_admin/pkg/di"
+)
+
+var Module = di.Options(
+	di.Provide(MustNewStore),
+)
+
+type DB struct {
+	*gorm.DB
+}
+
+func NewStore(engine *gorm.DB) *DB {
+	return &DB{engine}
+}
+
+type goRmLog struct {
+}
+
+func (g goRmLog) Printf(s string, i ...interface{}) {
+	logrus.Infof(s, i...)
+}
+
+func MustNewStore(cfg *config.AppConfig) *DB {
+	newLogger := logger.New(
+		goRmLog{},
+		logger.Config{
+			SlowThreshold: 5 * time.Second,
+			LogLevel:      logger.Info,
+		},
+	)
+
+	db, err := gorm.Open(mysql.New(mysql.Config{
+		DriverName: cfg.StoreSetting.DriverName,
+		DSN:        cfg.StoreSetting.KptEventDSNRW}),
+		&gorm.Config{Logger: newLogger},
+	)
+	if err != nil {
+		panic(xerr.WithStack(err))
+	}
+
+	if cfg.StoreSetting.ShowSQL {
+		db.Logger.LogMode(logger.Info)
+	}
+
+	return NewStore(db)
+}

+ 0 - 133
util/cleanup/entry.go

@@ -1,133 +0,0 @@
-// Package cleanup provides a single point for registering clean up functions.
-// This is similar to Finalizer, except that the clean up functions are
-// guaranteed to be called if the process terminates normally.
-//
-// Usage:
-//
-// In my_package.go
-//
-//   cleanup.Register(func(){
-//     // Arbitrary clean up function, most likely close goroutine, etc.
-//   })
-//
-// In main.go
-//
-//   func main() {
-//     flag.Parse()
-//     defer cleanup.Run()
-//   }
-package cleanup
-
-import (
-	"context"
-	"reflect"
-	"sync"
-
-	"kpt-event/util/logger"
-	"kpt-event/util/xerr"
-)
-
-// entry global cleanup entry
-var entry Entry
-
-// Register adds a function to the global cleanup queue.
-func Register(container interface{}) {
-	entry.Register(container)
-}
-
-// Run runs all the global cleanup functions registered.
-func Run() {
-	entry.Run()
-}
-
-type Entry struct {
-	mu   sync.Mutex
-	fns  []func()
-	once sync.Once
-}
-
-// Run runs all the cleanup functions registered.
-func (entry *Entry) Run() {
-	log.Infof("cleanup: performing %d cleanups", len(entry.fns))
-
-	entry.once.Do(func() {
-		for _, f := range entry.fns {
-			f()
-		}
-	})
-
-	log.Infof("cleanup: all done")
-}
-
-// Register adds a function to the cleanup queue.
-func (entry *Entry) Register(container interface{}) {
-	v := reflect.Indirect(reflect.ValueOf(container))
-	var err error
-	switch v.Kind() {
-	case reflect.Func:
-		err = entry.RegisterFunc(v.Interface())
-	case reflect.Struct:
-		err = entry.RegisterStruct(v.Interface())
-	default:
-		panic("cleanup: unsupported type")
-	}
-	if err != nil {
-		panic(err)
-	}
-}
-
-func (entry *Entry) RegisterStruct(ctor interface{}) error {
-	cValue := reflect.Indirect(reflect.ValueOf(ctor))
-	if cValue.Kind() != reflect.Struct {
-		return xerr.New("RegisterStruct receive a struct or ptr to struct")
-	}
-	for i := 0; i < cValue.NumField(); i++ {
-		field := cValue.Field(i)
-		if field.IsZero() {
-			continue
-		}
-		method := field.MethodByName("Close")
-		if !method.IsValid() {
-			method = field.MethodByName("Flush")
-		}
-		if method.IsValid() {
-			if err := entry.RegisterFunc(method.Interface()); err != nil {
-				log.WithError(err).WithField("fieldName", field.Type().Name()).Error("register func failed")
-			}
-		}
-	}
-	return nil
-}
-
-// RegisterFunc receive func() or func() error
-func (entry *Entry) RegisterFunc(fn interface{}) error {
-	fType := reflect.TypeOf(fn)
-	if fType.Kind() != reflect.Func {
-		return xerr.New("cleanup: unsupported type")
-	}
-	if fType.NumIn() > 0 {
-		return xerr.New("RegisterFunc receive func() or func() error")
-	}
-
-	if f, ok := fn.(func()); ok {
-		entry.register(f)
-		return nil
-	}
-	if f, ok := fn.(func() error); ok {
-		entry.register(func() {
-			if err := f(); err != nil {
-				_ = xerr.ReportError(context.Background(), err)
-			}
-		})
-		return nil
-	}
-	return xerr.New("RegisterFunc receive func() or func() error")
-}
-
-func (entry *Entry) register(fns ...func()) {
-	entry.mu.Lock()
-	defer entry.mu.Unlock()
-	for _, fn := range fns {
-		entry.fns = append(entry.fns, fn)
-	}
-}

+ 0 - 53
util/cleanup/entry_test.go

@@ -1,53 +0,0 @@
-package cleanup
-
-import (
-	"testing"
-)
-
-type f1 struct{}
-
-func (*f1) Close() {}
-
-type f2 struct{}
-
-func (*f2) Close() error { return nil }
-
-type f3 struct{}
-
-func (*f3) Flush() {}
-
-type f4 struct{}
-
-func (*f4) NoCloseOrFlush() {}
-
-type TestStruct struct {
-	F1 *f1
-	F2 *f2
-	F3 *f3
-	F4 *f4
-}
-
-func TestRegisterStruct(t *testing.T) {
-	var e Entry
-	s := TestStruct{
-		F1: &f1{},
-		F2: &f2{},
-		F3: &f3{},
-		F4: &f4{},
-	}
-	e.Register(s)
-}
-
-func TestCleanup(t *testing.T) {
-	var e Entry
-	i, j := 0, 0
-	func() {
-		e.Register(func() { i += 1 })
-		e.Register(func() { j += 2 })
-		e.Run()
-		e.Run() // multiple runs will be OK.
-	}()
-	if i != 1 || j != 2 {
-		t.Errorf("Run() incorrect, want i = 1, j = 2, got i = %d, j = %d", i, j)
-	}
-}

+ 0 - 19
util/cputil/cp.go

@@ -1,19 +0,0 @@
-package cputil
-
-import (
-	"github.com/jinzhu/copier"
-)
-
-func ShallowCopy(toValue interface{}, fromValue interface{}) error {
-	return copier.CopyWithOption(toValue, fromValue, copier.Option{
-		IgnoreEmpty: true,
-		DeepCopy:    false,
-	})
-}
-
-func DeepCopy(toValue interface{}, fromValue interface{}) error {
-	return copier.CopyWithOption(toValue, fromValue, copier.Option{
-		IgnoreEmpty: true,
-		DeepCopy:    true,
-	})
-}

+ 0 - 59
util/cputil/cp_test.go

@@ -1,59 +0,0 @@
-package cputil
-
-import (
-	"testing"
-
-	"github.com/google/go-cmp/cmp"
-	"github.com/stretchr/testify/require"
-)
-
-type Dummy struct {
-	A1 int
-	A2 int
-	B1 bool
-	B2 bool
-	C1 map[string]interface{}
-	D1 []int
-}
-
-func TestShallowCopy(t *testing.T) {
-	d1 := &Dummy{
-		A1: 0,
-		A2: 1,
-		B1: false,
-		B2: true,
-		C1: map[string]interface{}{
-			"a": 1,
-		},
-		D1: []int{0, 1},
-	}
-
-	d2 := &Dummy{}
-	_ = ShallowCopy(&d2, d1)
-	require.Empty(t, cmp.Diff(d1, d2))
-
-	// case: 浅拷贝会互相影响
-	d1.C1["a"] = 2
-	require.Equal(t, d2.C1["a"], d1.C1["a"])
-}
-
-func TestDeepCopy(t *testing.T) {
-	d1 := &Dummy{
-		A1: 0,
-		A2: 1,
-		B1: false,
-		B2: true,
-		C1: map[string]interface{}{
-			"a": 1,
-		},
-		D1: []int{0, 1},
-	}
-
-	d2 := &Dummy{}
-	_ = DeepCopy(&d2, d1)
-	require.Empty(t, cmp.Diff(d1, d2))
-
-	// case: 深拷贝不会互相影响
-	d1.C1["a"] = 2
-	require.NotEqual(t, d2.C1["a"], d1.C1["a"])
-}

+ 0 - 26
util/di/annotation.go

@@ -1,26 +0,0 @@
-package di
-
-type Annotated struct {
-	// If specified, this will be used as the name for all non-error values returned
-	// by the constructor. For more information on named values, see the documentation
-	// for the fx.Out type.
-	//
-	// A name option may not be provided if a group option is provided.
-	Name string
-
-	// If specified, this will be used as the group name for all non-error values returned
-	// by the constructor. For more information on value groups, see the package documentation.
-	//
-	// A group option may not be provided if a name option is provided.
-	//
-	// Similar to group tags, the group name may be followed by a `,flatten`
-	// option to indicate that each element in the slice returned by the
-	// constructor should be injected into the value group individually.
-	Group string
-
-	// Target is the constructor or value being annotated with fx.Annotated.
-	Target interface{}
-
-	// Close is the function being closed when container is destroy
-	Close interface{}
-}

+ 0 - 152
util/di/hub.go

@@ -1,152 +0,0 @@
-package di
-
-import (
-	"reflect"
-
-	"go.uber.org/dig"
-	"kpt-event/util/cleanup"
-	"kpt-event/util/di/xreflect"
-	"kpt-event/util/xerr"
-)
-
-func New(opts ...HubOption) (*Hub, error) {
-	hub := &Hub{
-		cleanup:  cleanup.Entry{},
-		provides: make([]Provided, 0),
-	}
-	for _, opt := range opts {
-		opt.Apply(hub)
-	}
-
-	hub.container = dig.New(
-		dig.DryRun(hub.validate),
-	)
-	for i, p := range hub.provides {
-		if err := hub.usingProvide(p); err != nil {
-			return nil, xerr.Errorf("error after options[%d] were applied: %v", i, err)
-		}
-	}
-
-	return hub, nil
-}
-
-// Hub is a directed acyclic graph of types and their dependencies.
-// extend dig.Container
-type Hub struct {
-	container *dig.Container
-	cleanup   cleanup.Entry
-	provides  []Provided
-	validate  bool
-}
-
-// Cleanup runs all the cleanup functions registered in the hub.
-func (hub *Hub) Cleanup() {
-	hub.cleanup.Run()
-}
-
-// Provided is a single constructor provided to di.
-type Provided struct {
-	// Constructor provided to di. This may be an di.Annotated.
-	Target interface{}
-
-	// Stack trace of where this Provided was made.
-	Stack xreflect.Stack
-
-	// IsSupply is true when the Target constructor was emitted by di.Supply.
-	IsSupply bool
-}
-
-func (hub *Hub) usingProvide(p Provided) error {
-	constructor := p.Target
-
-	if _, ok := constructor.(HubOption); ok {
-		return xerr.Errorf("di.Option should be passed to di.New directly, "+
-			"not to di.Provide: di.Provide received %v from:\n%+v",
-			constructor, p.Stack)
-	}
-
-	if ann, ok := constructor.(Annotated); ok {
-		var opts []dig.ProvideOption
-		switch {
-		case len(ann.Group) > 0 && len(ann.Name) > 0:
-			return xerr.Errorf(
-				"di.Annotated may specify only one of Name or Group: received %v from:\n%+v",
-				ann, p.Stack)
-		case len(ann.Name) > 0:
-			opts = append(opts, dig.Name(ann.Name))
-		case len(ann.Group) > 0:
-			opts = append(opts, dig.Group(ann.Group))
-
-		}
-
-		// 注册初始化函数
-		if err := hub.Provide(ann.Target, opts...); err != nil {
-			return xerr.Errorf("di.Provide(%v) from:\n%+vFailed: %v", ann, p.Stack, err)
-		}
-
-		// 注册清理函数
-		if ann.Close != nil {
-			hub.cleanup.Register(ann.Close)
-		}
-
-		return nil
-	}
-
-	if reflect.TypeOf(constructor).Kind() == reflect.Func {
-		ft := reflect.ValueOf(constructor).Type()
-
-		for i := 0; i < ft.NumOut(); i++ {
-			t := ft.Out(i)
-
-			if t == reflect.TypeOf(Annotated{}) {
-				return xerr.Errorf(
-					"di.Annotated should be passed to di.Provide directly, "+
-						"it should not be returned by the constructor: "+
-						"di.Provide received %v from:\n%+v",
-					xreflect.FuncName(constructor), p.Stack)
-			}
-		}
-	}
-
-	if err := hub.Provide(constructor); err != nil {
-		return xerr.Errorf("di.Provide(%v) from:\n%+vFailed: %v", xreflect.FuncName(constructor), p.Stack, err)
-	}
-
-	return nil
-}
-
-// Invoke runs the given function after instantiating its dependencies.
-//
-// Any arguments that the function has are treated as its dependencies. The
-// dependencies are instantiated in an unspecified order along with any
-// dependencies that they might have.
-//
-// The function may return an error to indicate failure. The error will be
-// returned to the caller as-is.
-func (hub *Hub) Invoke(function interface{}, opts ...InvokeOption) error {
-	return hub.container.Invoke(function, opts...)
-}
-
-// Provide teaches the container how to build values of one or more types and
-// expresses their dependencies.
-//
-// The first argument of Provide is a function that accepts zero or more
-// parameters and returns one or more results. The function may optionally
-// return an error to indicate that it failed to build the value. This
-// function will be treated as the constructor for all the types it returns.
-// This function will be called AT MOST ONCE when a type produced by it, or a
-// type that consumes this function's output, is requested via Invoke. If the
-// same types are requested multiple times, the previously produced value will
-// be reused.
-//
-// In addition to accepting constructors that accept dependencies as separate
-// arguments and produce results as separate return values, Provide also
-// accepts constructors that specify dependencies as dig.In structs and/or
-// specify results as dig.Out structs.
-func (hub *Hub) Provide(constructor interface{}, opts ...ProvideOption) error {
-	return hub.container.Provide(constructor, opts...)
-}
-
-func (hub *Hub) GetProvidedSlice() []Provided {
-	return hub.provides
-}

+ 0 - 187
util/di/hub_test.go

@@ -1,187 +0,0 @@
-package di
-
-import (
-	"strings"
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-	"go.uber.org/dig"
-)
-
-func TestHub_New(t *testing.T) {
-	t.Run("basic di", func(t *testing.T) {
-		hub, err := New(module1, ValidateHub(true))
-		require.NoError(t, err)
-		require.NotNil(t, hub)
-
-		err = hub.Invoke(func(c C) {
-			assert.Equal(t, c.Number, int64(100))
-		})
-		require.NoError(t, err)
-
-		err = hub.Invoke(func(d D) {
-			assert.Equal(t, d.C.Number, int64(100))
-		})
-		require.NoError(t, err)
-
-		err = hub.Invoke(func(f1 F1) {
-			assert.Equal(t, f1.Name, "f1")
-		})
-		require.NoError(t, err)
-	})
-
-	t.Run("annotation", func(t *testing.T) {
-		k0 := &K0{}
-		hub, err := New(module2, Annotation(func(ann *Annotated) {
-			ann.Target = func() *K0 { return k0 }
-			ann.Close = k0.Close
-		}))
-		require.NoError(t, err)
-		require.NotNil(t, hub)
-
-		// invoke now
-		err = hub.Invoke(func(k1 K1) { assert.Equal(t, k1.J.Name, "j1") })
-		require.NoError(t, err)
-		err = hub.Invoke(func(k2 K2) { assert.Equal(t, k2.J.Name, "j2") })
-		require.NoError(t, err)
-
-		// cleanup and check it
-		hub.Cleanup()
-		require.True(t, k0.Closed)
-	})
-
-	t.Run("missing deps", func(t *testing.T) {
-		hub, err := New(moduleFailed, ValidateHub(false))
-		require.NoError(t, err) // won't check missing H in G, only check it after invoke
-		require.NotNil(t, hub)
-
-		err = hub.Invoke(func(g G) {})
-		assert.Error(t, err)
-		assert.True(t, strings.Contains(err.Error(), "missing dependencies"))
-	})
-}
-
-var module1 = Options(
-	Provide(func() A {
-		return A{Name: "a"}
-	}),
-	Provide(func(a A) B {
-		return B{
-			A:   a,
-			Age: 20,
-		}
-	}),
-	Provide(func(a A, b B) C {
-		return C{
-			A:      a,
-			B:      b,
-			Number: 100,
-		}
-	}),
-	Provide(NewE),
-)
-
-var module2 = Options(
-	Provide(Annotated{
-		Name: "j1",
-		Target: func() J {
-			return J{Name: "j1"}
-		},
-	}),
-	Provide(Annotated{
-		Name: "j2",
-		Target: func() J {
-			return J{Name: "j2"}
-		},
-	}),
-)
-
-var moduleFailed = Options(
-	Provide(func(g G) H {
-		return H{
-			G:    g,
-			Name: "h",
-		}
-	}),
-)
-
-type A struct {
-	Name string
-}
-
-type B struct {
-	A   A
-	Age int
-}
-
-type C struct {
-	A      A
-	B      B
-	Number int64
-}
-
-type D struct {
-	dig.In
-
-	A A
-	B B
-	C C
-}
-
-func NewE() E {
-	return E{
-		F1: F1{
-			Name: "f1",
-		},
-		F2: F2{
-			Name: "f2",
-		},
-	}
-}
-
-type E struct {
-	dig.Out
-
-	F1 F1
-	F2 F2
-}
-
-type F1 struct {
-	Name string
-}
-
-type F2 struct {
-	Name string
-}
-
-type G struct {
-	Name string
-}
-
-type H struct {
-	G    G
-	Name string
-}
-
-type J struct {
-	Name string
-}
-
-type K0 struct {
-	Closed bool
-}
-
-func (k *K0) Close() {
-	k.Closed = true
-}
-
-type K1 struct {
-	dig.In
-	J J `name:"j1"`
-}
-
-type K2 struct {
-	dig.In
-	J J `name:"j2"`
-}

+ 0 - 179
util/di/option.go

@@ -1,179 +0,0 @@
-package di
-
-import (
-	"fmt"
-	"strings"
-
-	"go.uber.org/dig"
-	"kpt-event/util/di/xreflect"
-)
-
-// Option configures a Hub. It's included for future functionality;
-// currently, there are no concrete implementations.
-type Option = dig.Option
-
-// A ProvideOption modifies the default behavior of Provide.
-type ProvideOption = dig.ProvideOption
-
-// An InvokeOption modifies the default behavior of Invoke. It's included for
-// future functionality; currently, there are no concrete implementations.
-type InvokeOption = dig.InvokeOption
-
-// HubOption is an option configures an Hub using the functional options paradigm
-// popularized by Rob Pike. If you're unfamiliar with this style, see
-// https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html.
-type HubOption interface {
-	fmt.Stringer
-	Apply(hub *Hub)
-}
-
-// Options converts a collection of Options into a single Option. This allows
-// packages to bundle sophisticated functionality into easy-to-use Fx modules.
-// For example, a logging package might export a simple option like this:
-//
-//  package logging
-//
-//  var Module = fx.Provide(func() *log.Logger {
-//    return log.New(os.Stdout, "", 0)
-//  })
-//
-// A shared all-in-one microservice package could then use Options to bundle
-// logging with similar metrics, tracing, and gRPC modules:
-//
-//  package server
-//
-//  var Module = fx.Options(
-//    logging.Module,
-//    metrics.Module,
-//    tracing.Module,
-//    grpc.Module,
-//  )
-//
-// Since this all-in-one module1 has a minimal API surface, it's easy to add
-// new functionality to it without breaking existing users. Individual
-// applications can take advantage of all this functionality with only one
-// line of code:
-//
-//  app := di.New(server.Module)
-//
-// Use this pattern sparingly, since it limits the user's ability to customize
-// their application.
-func Options(opts ...HubOption) HubOption {
-	return optionGroup(opts)
-}
-
-type optionGroup []HubOption
-
-func (og optionGroup) Apply(hub *Hub) {
-	for _, opt := range og {
-		opt.Apply(hub)
-	}
-}
-
-func (og optionGroup) String() string {
-	items := make([]string, len(og))
-	for i, opt := range og {
-		items[i] = fmt.Sprint(opt)
-	}
-	return fmt.Sprintf("di.Options(%s)", strings.Join(items, ", "))
-}
-
-// Annotation define annotated and apply to Provided
-// Annotation provides instantiated values for dependency injection as if
-// they had been provided using a constructor that simply returns them.
-// The most specific type of each value (as determined by reflection) is used.
-//
-//	type K0 struct {
-//		Closed bool
-//	}
-//
-//	func (k *K0) Close() {
-//		k.Closed = true
-//	}
-//
-//	k0 := &K0{}
-//	var module = Annotation(func(ann *Annotated) {
-//		ann.Target = func() *K0 { return k0 }
-//		ann.Close = k0.Close
-//	})
-//
-//	hub, err := di.New(module)
-func Annotation(f func(ann *Annotated)) HubOption {
-	annotation := &Annotated{}
-	f(annotation)
-
-	return provideOption{
-		Targets: []interface{}{*annotation},
-		Stack:   xreflect.CallerStack(1, 0),
-	}
-}
-
-// Provide registers any number of constructor functions, teaching the
-// application how to instantiate various types. The supplied constructor
-// function(s) may depend on other types available in the application, must
-// return one or more objects, and may return an error. For example:
-//
-//  // Constructs type *C, depends on *A and *B.
-//  func(*A, *B) *C
-//
-//  // Constructs type *C, depends on *A and *B, and indicates failure by
-//  // returning an error.
-//  func(*A, *B) (*C, error)
-//
-//  // Constructs types *B and *C, depends on *A, and can fail.
-//  func(*A) (*B, *C, error)
-func Provide(constructors ...interface{}) HubOption {
-	// check no nil or error
-	for _, value := range constructors {
-		switch value.(type) {
-		case nil:
-			panic("untyped nil passed to di.Provide")
-		case error:
-			panic("error value passed to di.Provide")
-		}
-	}
-
-	return provideOption{
-		Targets: constructors,
-		Stack:   xreflect.CallerStack(1, 0),
-	}
-}
-
-type provideOption struct {
-	Targets []interface{}
-	Stack   xreflect.Stack
-}
-
-func (o provideOption) Apply(hub *Hub) {
-	for _, target := range o.Targets {
-		hub.provides = append(hub.provides, Provided{
-			Target: target,
-			Stack:  o.Stack,
-		})
-	}
-}
-
-func (o provideOption) String() string {
-	items := make([]string, len(o.Targets))
-	for i, c := range o.Targets {
-		items[i] = xreflect.FuncName(c)
-	}
-	return fmt.Sprintf("fx.Provide(%s)", strings.Join(items, ", "))
-}
-
-// ValidateHub validates that supplied graph would run and is not missing any dependencies.
-func ValidateHub(v bool) HubOption {
-	return validateOption{validate: v}
-}
-
-type validateOption struct {
-	validate bool
-}
-
-func (o validateOption) Apply(hub *Hub) {
-	hub.validate = o.validate
-}
-
-func (o validateOption) String() string {
-	return fmt.Sprintf("fx.validate(%v)", o.validate)
-}

+ 0 - 157
util/di/xreflect/reflect.go

@@ -1,157 +0,0 @@
-// Copyright (c) 2019 Uber Technologies, Inc.
-//
-// 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.
-
-package xreflect
-
-import (
-	"fmt"
-	"net/url"
-	"reflect"
-	"regexp"
-	"runtime"
-	"strings"
-
-	"go.uber.org/dig"
-)
-
-// Match from beginning of the line until the first `vendor/` (non-greedy)
-var vendorRe = regexp.MustCompile("^.*?/vendor/")
-
-// ReturnTypes takes a func and returns a slice of string'd types.
-func ReturnTypes(t interface{}) []string {
-	if reflect.TypeOf(t).Kind() != reflect.Func {
-		// Invalid provide, will be logged as an error.
-		return []string{}
-	}
-
-	rtypes := []string{}
-	ft := reflect.ValueOf(t).Type()
-
-	for i := 0; i < ft.NumOut(); i++ {
-		t := ft.Out(i)
-
-		traverseOuts(key{t: t}, func(s string) {
-			rtypes = append(rtypes, s)
-		})
-	}
-
-	return rtypes
-}
-
-type key struct {
-	t    reflect.Type
-	name string
-}
-
-func (k *key) String() string {
-	if k.name != "" {
-		return fmt.Sprintf("%v:%s", k.t, k.name)
-	}
-	return k.t.String()
-}
-
-func traverseOuts(k key, f func(s string)) {
-	// skip errors
-	if isErr(k.t) {
-		return
-	}
-
-	// call function on non-Out types
-	if dig.IsOut(k.t) {
-		// keep recursing down on field members in case they are ins
-		for i := 0; i < k.t.NumField(); i++ {
-			field := k.t.Field(i)
-			ft := field.Type
-
-			if field.PkgPath != "" {
-				continue // skip private fields
-			}
-
-			// keep recursing to traverse all the embedded objects
-			k := key{
-				t:    ft,
-				name: field.Tag.Get("name"),
-			}
-			traverseOuts(k, f)
-		}
-
-		return
-	}
-
-	f(k.String())
-}
-
-// sanitize makes the function name suitable for logging display. It removes
-// url-encoded elements from the `dot.git` package names and shortens the
-// vendored paths.
-func sanitize(function string) string {
-	// Use the stdlib to un-escape any package import paths which can happen
-	// in the case of the "dot-git" postfix. Seems like a bug in stdlib =/
-	if unescaped, err := url.QueryUnescape(function); err == nil {
-		function = unescaped
-	}
-
-	// strip everything prior to the vendor
-	return vendorRe.ReplaceAllString(function, "vendor/")
-}
-
-// Caller returns the formatted calling func name
-func Caller() string {
-	return CallerStack(1, 0).CallerName()
-}
-
-// FuncName returns a funcs formatted name
-func FuncName(fn interface{}) string {
-	fnV := reflect.ValueOf(fn)
-	if fnV.Kind() != reflect.Func {
-		return fmt.Sprint(fn)
-	}
-
-	function := runtime.FuncForPC(fnV.Pointer()).Name()
-	return fmt.Sprintf("%s()", sanitize(function))
-}
-
-func isErr(t reflect.Type) bool {
-	errInterface := reflect.TypeOf((*error)(nil)).Elem()
-	return t.Implements(errInterface)
-}
-
-// Ascend the call stack until we leave the di production code. This allows us
-// to avoid hard-coding a frame skip, which makes this code work well even
-// when it's wrapped.
-func shouldIgnoreFrame(f Frame) bool {
-	// Treat test files as leafs.
-	if strings.Contains(f.File, "_test.go") {
-		return false
-	}
-
-	// The unique, fully-qualified name for all functions begins with
-	// "{{importPath}}.". We'll ignore di and its subpackages.
-	s := strings.TrimPrefix(f.Function, "git.llsapp.com/zhenghe/pkg/di")
-	if len(s) > 0 && s[0] == '.' || s[0] == '/' {
-		// We want to match,
-		//   git.llsapp.com/zhenghe/pkg/di.Foo
-		//   git.llsapp.com/zhenghe/pkg/di/something.Foo
-		// But not, git.llsapp.com/zhenghe/pkg/difoo
-		return true
-	}
-
-	return false
-}

+ 0 - 143
util/di/xreflect/reflect_test.go

@@ -1,143 +0,0 @@
-// Copyright (c) 2019 Uber Technologies, Inc.
-//
-// 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.
-
-package xreflect
-
-import (
-	"errors"
-	"log"
-	"sync"
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-	"go.uber.org/dig"
-)
-
-type hollerer interface {
-	Holler()
-}
-
-type impl struct{}
-
-func (impl) Holler() {}
-
-type result struct {
-	dig.Out // referencing di introduces import cycles
-
-	mu     sync.Mutex // unexported
-	Logger *log.Logger
-}
-
-func TestReturnTypes(t *testing.T) {
-	t.Run("non-function", func(t *testing.T) {
-		assert.Empty(t, ReturnTypes(42))
-	})
-	t.Run("primitive", func(t *testing.T) {
-		fn := func() (int, string) {
-			return 0, ""
-		}
-		assert.Equal(t, []string{"int", "string"}, ReturnTypes(fn))
-	})
-	t.Run("pointer", func(t *testing.T) {
-		type s struct{}
-		fn := func() *s {
-			return &s{}
-		}
-		assert.Equal(t, []string{"*xreflect.s"}, ReturnTypes(fn))
-	})
-	t.Run("interface", func(t *testing.T) {
-		fn := func() hollerer {
-			return impl{}
-		}
-		assert.Equal(t, []string{"xreflect.hollerer"}, ReturnTypes(fn))
-	})
-	t.Run("result struct", func(t *testing.T) {
-		fn := func() result {
-			return result{}
-		}
-		assert.Equal(t, []string{"*log.Logger"}, ReturnTypes(fn))
-	})
-	t.Run("skips errors", func(t *testing.T) {
-		fn := func() (string, error) {
-			return "", errors.New("err")
-		}
-		assert.Equal(t, []string{"string"}, ReturnTypes(fn))
-	})
-}
-
-func TestCaller(t *testing.T) {
-	assert.Equal(t, "git.llsapp.com/zhenghe/pkg/di/xreflect.TestCaller", Caller())
-}
-
-func someFunc() {}
-
-func TestFuncName(t *testing.T) {
-	tests := []struct {
-		desc string
-		give interface{}
-		want string
-	}{
-		{
-			desc: "function",
-			give: someFunc,
-			want: "git.llsapp.com/zhenghe/pkg/di/xreflect.someFunc()",
-		},
-		{
-			desc: "not a function",
-			give: 42,
-			want: "42",
-		},
-	}
-
-	for _, tt := range tests {
-		t.Run(tt.desc, func(t *testing.T) {
-			assert.Equal(t, tt.want, FuncName(tt.give))
-		})
-	}
-}
-
-func TestSanitizeFuncNames(t *testing.T) {
-	cases := []struct {
-		name     string
-		input    string
-		expected string
-	}{
-		{
-			"url encoding",
-			"go.uber.org/di/sample%2egit/someFunc",
-			"go.uber.org/di/sample.git/someFunc",
-		},
-		{
-			"vendor removal",
-			"go.uber.org/di/vendor/github.com/some/lib.SomeFunc",
-			"vendor/github.com/some/lib.SomeFunc",
-		},
-		{
-			"package happens to be named vendor is untouched",
-			"go.uber.org/di/foovendor/someFunc",
-			"go.uber.org/di/foovendor/someFunc",
-		},
-	}
-	for _, c := range cases {
-		t.Run(c.name, func(t *testing.T) {
-			assert.Equal(t, c.expected, sanitize(c.input))
-		})
-	}
-}

+ 0 - 149
util/di/xreflect/stack.go

@@ -1,149 +0,0 @@
-// Copyright (c) 2019 Uber Technologies, Inc.
-//
-// 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.
-
-package xreflect
-
-import (
-	"fmt"
-	"io"
-	"runtime"
-	"strings"
-)
-
-// Frame holds information about a single frame in the call stack.
-type Frame struct {
-	// Unique, package path-qualified name for the function of this call
-	// frame.
-	Function string
-
-	// File and line number of our location in the frame.
-	//
-	// Note that the line number does not refer to where the function was
-	// defined but where in the function the next call was made.
-	File string
-	Line int
-}
-
-func (f Frame) String() string {
-	// This takes the following forms.
-	//  (path/to/file.go)
-	//  (path/to/file.go:42)
-	//  path/to/package.MyFunction
-	//  path/to/package.MyFunction (path/to/file.go)
-	//  path/to/package.MyFunction (path/to/file.go:42)
-
-	var sb strings.Builder
-	sb.WriteString(f.Function)
-	if len(f.File) > 0 {
-		if sb.Len() > 0 {
-			sb.WriteRune(' ')
-		}
-		fmt.Fprintf(&sb, "(%v", f.File)
-		if f.Line > 0 {
-			fmt.Fprintf(&sb, ":%d", f.Line)
-		}
-		sb.WriteRune(')')
-	}
-
-	if sb.Len() == 0 {
-		return "unknown"
-	}
-
-	return sb.String()
-}
-
-const _defaultCallersDepth = 8
-
-// Stack is a stack of call frames.
-//
-// Formatted with %v, the output is in a single-line, in the form,
-//
-//   foo/bar.Baz() (path/to/foo.go:42); bar/baz.Qux() (bar/baz/qux.go:12); ...
-//
-// Formatted with %+v, the output is in the form,
-//
-//   foo/bar.Baz()
-//   	path/to/foo.go:42
-//   bar/baz.Qux()
-//   	bar/baz/qux.go:12
-type Stack []Frame
-
-// Returns a single-line, semi-colon representation of a Stack. For a
-// multi-line representation, use %+v.
-func (fs Stack) String() string {
-	items := make([]string, len(fs))
-	for i, f := range fs {
-		items[i] = f.String()
-	}
-	return strings.Join(items, "; ")
-}
-
-// Format implements fmt.Formatter to handle "%+v".
-func (fs Stack) Format(w fmt.State, c rune) {
-	if !w.Flag('+') {
-		// Without %+v, fall back to String().
-		io.WriteString(w, fs.String())
-		return
-	}
-
-	for _, f := range fs {
-		fmt.Fprintln(w, f.Function)
-		fmt.Fprintf(w, "\t%v:%v\n", f.File, f.Line)
-	}
-}
-
-// CallerName returns the name of the first caller in this stack that isn't
-// owned by the di library.
-func (fs Stack) CallerName() string {
-	for _, f := range fs {
-		if shouldIgnoreFrame(f) {
-			continue
-		}
-		return f.Function
-	}
-	return "n/a"
-}
-
-// CallerStack returns the call stack for the calling function, up to depth frames
-// deep, skipping the provided number of frames, not including Callers itself.
-//
-// If zero, depth defaults to 8.
-func CallerStack(skip, depth int) Stack {
-	if depth <= 0 {
-		depth = _defaultCallersDepth
-	}
-
-	pcs := make([]uintptr, depth)
-
-	// +2 to skip this frame and runtime.Callers.
-	n := runtime.Callers(skip+2, pcs)
-	pcs = pcs[:n] // truncate to number of frames actually read
-
-	result := make([]Frame, 0, n)
-	frames := runtime.CallersFrames(pcs)
-	for f, more := frames.Next(); more; f, more = frames.Next() {
-		result = append(result, Frame{
-			Function: sanitize(f.Function),
-			File:     f.File,
-			Line:     f.Line,
-		})
-	}
-	return result
-}

+ 0 - 236
util/di/xreflect/stack_test.go

@@ -1,236 +0,0 @@
-// Copyright (c) 2019 Uber Technologies, Inc.
-//
-// 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.
-
-package xreflect
-
-import (
-	"fmt"
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-)
-
-func TestStack(t *testing.T) {
-	// NOTE:
-	// We don't assert the length of the stack because we cannot make
-	// guarantees about how many frames the test runner is allowed to
-	// introduce.
-
-	t.Run("default", func(t *testing.T) {
-		frames := CallerStack(0, 0)
-		require.NotEmpty(t, frames)
-		f := frames[0]
-		assert.Equal(t, "git.llsapp.com/zhenghe/pkg/di/xreflect.TestStack.func1", f.Function)
-		assert.Contains(t, f.File, "xreflect/stack_test.go")
-		assert.NotZero(t, f.Line)
-	})
-
-	t.Run("default/deeper", func(t *testing.T) {
-		// Introduce a few frames.
-		frames := func() []Frame {
-			return func() []Frame {
-				return CallerStack(0, 0)
-			}()
-		}()
-
-		require.True(t, len(frames) > 3, "expected at least three frames")
-		for i, name := range []string{"func2.1.1", "func2.1", "func2"} {
-			f := frames[i]
-			assert.Equal(t, "git.llsapp.com/zhenghe/pkg/di/xreflect.TestStack."+name, f.Function)
-			assert.Contains(t, f.File, "xreflect/stack_test.go")
-			assert.NotZero(t, f.Line)
-		}
-	})
-
-	t.Run("skip", func(t *testing.T) {
-		// Introduce a few frames and skip 2.
-		frames := func() []Frame {
-			return func() []Frame {
-				return CallerStack(2, 0)
-			}()
-		}()
-
-		require.NotEmpty(t, frames)
-		f := frames[0]
-		assert.Equal(t, "git.llsapp.com/zhenghe/pkg/di/xreflect.TestStack.func3", f.Function)
-		assert.Contains(t, f.File, "xreflect/stack_test.go")
-		assert.NotZero(t, f.Line)
-	})
-}
-
-func TestStackCallerName(t *testing.T) {
-	tests := []struct {
-		desc string
-		give Stack
-		want string
-	}{
-		{desc: "empty", want: "n/a"},
-		{
-			desc: "skip di components",
-			give: Stack{
-				{
-					Function: "git.llsapp.com/zhenghe/pkg/di.Foo()",
-					File:     "git.llsapp.com/zhenghe/pkg/di/foo.go",
-				},
-				{
-					Function: "foo/bar.Baz()",
-					File:     "foo/bar/baz.go",
-				},
-			},
-			want: "foo/bar.Baz()",
-		},
-		{
-			desc: "skip di in wrong directory",
-			give: Stack{
-				{
-					Function: "git.llsapp.com/zhenghe/pkg/di/di.Foo()",
-					File:     "di/foo.go",
-				},
-				{
-					Function: "foo/bar.Baz()",
-					File:     "foo/bar/baz.go",
-				},
-			},
-			want: "foo/bar.Baz()",
-		},
-		{
-			desc: "skip di subpackage",
-			give: Stack{
-				{
-					Function: "git.llsapp.com/zhenghe/pkg/di/xreflect.Foo()",
-					File:     "di/internal/xreflect/foo.go",
-				},
-				{
-					Function: "foo/bar.Baz()",
-					File:     "foo/bar/baz.go",
-				},
-			},
-			want: "foo/bar.Baz()",
-		},
-		{
-			desc: "don't skip di tests",
-			give: Stack{
-				{
-					Function: "some/thing.Foo()",
-					File:     "git.llsapp.com/zhenghe/pkg/di/foo_test.go",
-				},
-			},
-			want: "some/thing.Foo()",
-		},
-		{
-			desc: "don't skip di prefix",
-			give: Stack{
-				{
-					Function: "git.llsapp.com/zhenghe/pkg/difoo.Bar()",
-					File:     "git.llsapp.com/zhenghe/pkg/difoo/bar.go",
-				},
-			},
-			want: "git.llsapp.com/zhenghe/pkg/difoo.Bar()",
-		},
-	}
-
-	for _, tt := range tests {
-		t.Run(tt.desc, func(t *testing.T) {
-			assert.Equal(t, tt.want, tt.give.CallerName())
-		})
-	}
-}
-
-func TestFrameString(t *testing.T) {
-	tests := []struct {
-		desc string
-		give Frame
-		want string
-	}{
-		{
-			desc: "zero",
-			give: Frame{},
-			want: "unknown",
-		},
-		{
-			desc: "file and line",
-			give: Frame{File: "foo.go", Line: 42},
-			want: "(foo.go:42)",
-		},
-		{
-			desc: "file only",
-			give: Frame{File: "foo.go"},
-			want: "(foo.go)",
-		},
-		{
-			desc: "function only",
-			give: Frame{Function: "foo"},
-			want: "foo",
-		},
-		{
-			desc: "function and file",
-			give: Frame{Function: "foo", File: "bar.go"},
-			want: "foo (bar.go)",
-		},
-		{
-			desc: "function and line",
-			give: Frame{Function: "foo", Line: 42},
-			want: "foo", // line without file is meaningless
-		},
-		{
-			desc: "function, file, and line",
-			give: Frame{Function: "foo", File: "bar.go", Line: 42},
-			want: "foo (bar.go:42)",
-		},
-	}
-
-	for _, tt := range tests {
-		t.Run(tt.desc, func(t *testing.T) {
-			assert.Equal(t, tt.want, tt.give.String())
-		})
-	}
-}
-
-func TestStackFormat(t *testing.T) {
-	stack := Stack{
-		{
-			Function: "path/to/module.SomeFunction()",
-			File:     "path/to/file.go",
-			Line:     42,
-		},
-		{
-			Function: "path/to/another/module.AnotherFunction()",
-			File:     "path/to/another/file.go",
-			Line:     12,
-		},
-	}
-
-	t.Run("single line", func(t *testing.T) {
-		assert.Equal(t,
-			"path/to/module.SomeFunction() (path/to/file.go:42); "+
-				"path/to/another/module.AnotherFunction() (path/to/another/file.go:12)",
-			fmt.Sprintf("%v", stack))
-	})
-
-	t.Run("multi line", func(t *testing.T) {
-		assert.Equal(t, `path/to/module.SomeFunction()
-	path/to/file.go:42
-path/to/another/module.AnotherFunction()
-	path/to/another/file.go:12
-`, fmt.Sprintf("%+v", stack))
-	})
-
-}

+ 0 - 192
util/logger/log.go

@@ -1,192 +0,0 @@
-package log
-
-import (
-	"fmt"
-	"os"
-	"path"
-	"runtime"
-
-	"github.com/sirupsen/logrus"
-)
-
-func init() {
-	// Log as JSON instead of the default ASCII formatter.
-	logrus.SetFormatter(&logrus.JSONFormatter{
-		CallerPrettyfier: func(f *runtime.Frame) (string, string) {
-			filename := path.Base(f.File)
-			return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line)
-		},
-	})
-
-	// Output to stdout instead of the default stderr
-	// Can be any io.Writer, see below for File example
-	logrus.SetOutput(os.Stdout)
-
-	// Only log the warning severity or above.
-	logrus.SetLevel(DebugLevel)
-}
-
-// These are the different logging levels. You can set the logging level to log
-// on your instance of logger, obtained with `logrus.New()`.
-const (
-	// PanicLevel level, highest level of severity. Logs and then calls panic with the
-	// message passed to Debug, Info, ...
-	PanicLevel Level = iota
-	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
-	// logging level is set to Panic.
-	FatalLevel
-	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
-	// Commonly used for hooks to send errors to an error tracking service.
-	ErrorLevel
-	// WarnLevel level. Non-critical entries that deserve eyes.
-	WarnLevel
-	// InfoLevel level. General operational entries about what's going on inside the
-	// application.
-	InfoLevel
-	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
-	DebugLevel
-	// TraceLevel level. Designates finer-grained informational events than the Debug.
-	TraceLevel
-)
-
-// Entry is the final or intermediate Logrus logging entry. It contains all
-// the fields passed with WithField{,s}. It's finally logged when Debug, Info,
-// Warn, Error, Fatal or Panic is called on it. These objects can be reused and
-// passed around as much as you wish to avoid field duplication.
-type Entry = logrus.Entry
-
-// Fields type, used to pass to `WithFields`.
-type Fields = logrus.Fields
-
-// FieldMap allows customization of the key names for default fields.
-type FieldMap = logrus.FieldMap
-
-// Level type
-type Level = logrus.Level
-
-// Logger type
-type Logger = logrus.Logger
-
-// JSONFormatter formats logs into parsable json
-type JSONFormatter struct {
-	logrus.JSONFormatter
-}
-
-// TextFormatter formats logs into text
-type TextFormatter struct {
-	logrus.TextFormatter
-}
-
-// Formatter
-// The Formatter interface is used to implement a custom Formatter. It takes an
-// `Entry`. It exposes all the fields, including the default ones:
-//
-// * `entry.Data["msg"]`. The message passed from Info, Warn, Error ..
-// * `entry.Data["time"]`. The timestamp.
-// * `entry.Data["level"]. The level the entry was logged at.
-//
-// Any additional fields added with `WithField` or `WithFields` are also in
-// `entry.Data`. Format is expected to return an array of bytes which are then
-// logged to `logger.Out`.
-
-// SetLevel ...
-func SetLevel(level Level) {
-	logrus.SetLevel(level)
-}
-
-// NewWithFields returns a logrus Entry with fields
-func NewWithFields(fields Fields) *Entry {
-	return logrus.WithFields(fields)
-}
-
-// NewEntry return an entry is the final or intermediate Logrus logging entry
-func NewEntry(logger *Logger) *Entry {
-	return logrus.NewEntry(logger)
-}
-
-// Exported from logrus
-var (
-	// Creates a new logger. Configuration should be set by changing `Formatter`,
-	// `Out` and `Hooks` directly on the default logger instance. You can also just
-	// instantiate your own:
-	//
-	//    var log = &Logger{
-	//      Out: os.Stderr,
-	//      Formatter: new(JSONFormatter),
-	//      Level: logrus.DebugLevel,
-	//    }
-	//
-	// It's recommended to make this a global instance called `log`.
-	New = logrus.New
-	// StandardLogger default logger
-	StandardLogger = logrus.StandardLogger
-	// SetOutput sets the standard logger output.
-	SetOutput = logrus.SetOutput
-	// SetFormatter sets the standard logger formatter.
-	SetFormatter = logrus.SetFormatter
-	// WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
-	WithError = logrus.WithError
-	// WithField creates an entry from the standard logger and adds a field to
-	// it. If you want multiple fields, use `WithFields`.
-	//
-	// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
-	// or Panic on the Entry it returns.
-	WithField = logrus.WithField
-	// WithFields creates an entry from the standard logger and adds multiple
-	// fields to it. This is simply a helper for `WithField`, invoking it
-	// once for each field.
-	//
-	// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
-	// or Panic on the Entry it returns.
-	WithFields = logrus.WithFields
-
-	// Debug logs a message at level Debug on the standard logger.
-	Debug = logrus.Debug
-	// Print logs a message at level Info on the standard logger.
-	Print = logrus.Print
-	// Info logs a message at level Info on the standard logger.
-	Info = logrus.Info
-	// Warn logs a message at level Warn on the standard logger.
-	Warn = logrus.Warn
-	// Warning logs a message at level Warn on the standard logger.
-	Warning = logrus.Warning
-	// Error logs a message at level Error on the standard logger.
-	Error = logrus.Error
-	// Panic logs a message at level Panic on the standard logger.
-	Panic = logrus.Panic
-	// Fatal logs a message at level Fatal on the standard logger.
-	Fatal = logrus.Fatal
-
-	// Debugf logs a message at level Debug on the standard logger.
-	Debugf = logrus.Debugf
-	// Printf logs a message at level Info on the standard logger.
-	Printf = logrus.Printf
-	// Infof logs a message at level Info on the standard logger.
-	Infof = logrus.Infof
-	// Warnf logs a message at level Warn on the standard logger.
-	Warnf = logrus.Warnf
-	// Warningf logs a message at level Warn on the standard logger.
-	Warningf = logrus.Warningf
-	// Errorf logs a message at level Error on the standard logger.
-	Errorf = logrus.Errorf
-	// Panicf logs a message at level Panic on the standard logger.
-	Panicf = logrus.Panicf
-	// Fatalf logs a message at level Fatal on the standard logger.
-	Fatalf = logrus.Fatalf
-	// Debugln logs a message at level Debug on the standard logger.
-	Debugln = logrus.Debugln
-	// Println logs a message at level Info on the standard logger.
-	Println = logrus.Println
-	// Infoln logs a message at level Info on the standard logger.
-	Infoln = logrus.Infoln
-	// Warnln logs a message at level Warn on the standard logger.
-	Warnln = logrus.Warnln
-	// Warningln logs a message at level Warn on the standard logger.
-	Warningln = logrus.Warningln
-	// Errorln logs a message at level Error on the standard logger.
-	Errorln = logrus.Errorln
-	// Panicln logs a message at level Panic on the standard logger.
-	Panicln = logrus.Panicln
-	// Fatalln logs a message at level Fatal on the standard logger.
-	Fatalln = logrus.Fatalln
-)

+ 0 - 37
util/runtimeutil/caller.go

@@ -1,37 +0,0 @@
-package runtimeutil
-
-import (
-	"fmt"
-	"runtime"
-	"strings"
-)
-
-// CallerFuncPos get caller's func name
-func CallerFuncPos(skip int) string {
-	_, line, name := Caller(skip + 1)
-	return fmt.Sprintf("%s:%d", name, line)
-}
-
-// CallerFuncPos get caller's func name
-func CallerFuncName(skip int) string {
-	_, _, name := Caller(skip + 1)
-	arr := strings.Split(name, "/")
-	if len(arr) >= 3 {
-		return strings.Join(arr[2:], ".")
-	}
-	return strings.Join(arr, ".")
-}
-
-// Caller file, file line, function name
-func Caller(skip int) (file string, line int, functionName string) {
-	var (
-		pc uintptr
-		ok bool
-	)
-	pc, file, line, ok = runtime.Caller(skip + 1)
-	if !ok {
-		return
-	}
-
-	return file, line, runtime.FuncForPC(pc).Name()
-}

+ 0 - 43
util/runtimeutil/caller_test.go

@@ -1,43 +0,0 @@
-package runtimeutil
-
-import (
-	"strings"
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-)
-
-func TestCallerFuncPos(t *testing.T) {
-	assert.True(t, strings.Contains(moo(), "TestCallerFuncPos:"))
-}
-
-func TestCaller(t *testing.T) {
-	assert.True(t, strings.Contains(foo(1), "TestCaller"))
-	assert.True(t, strings.Contains(bar(2), "TestCaller"))
-
-	file, line, funcName := Caller(0)
-	assert.True(t, strings.Contains(file, "caller_test.go"))
-	assert.True(t, strings.Contains(funcName, ".TestCaller"))
-	assert.True(t, line != 0)
-}
-
-func TestCallerFuncName(t *testing.T) {
-	assert.True(t, strings.Contains(baz(), "TestCallerFuncName"))
-}
-
-func foo(skip int) string {
-	_, _, s := Caller(skip)
-	return s
-}
-
-func bar(skip int) string {
-	return foo(skip)
-}
-
-func moo() string {
-	return CallerFuncPos(1)
-}
-
-func baz() string {
-	return CallerFuncName(1)
-}

+ 0 - 71
util/sentry/sentry.go

@@ -1,71 +0,0 @@
-package sentry
-
-import (
-	"context"
-	"github.com/getsentry/sentry-go"
-	log "kpt-event/util/logger"
-)
-
-func MustInit(dsn string, options ...*sentry.ClientOptions) {
-	var option *sentry.ClientOptions
-	if len(options) != 0 {
-		option = options[0]
-	} else {
-		option = &sentry.ClientOptions{
-			Dsn:              dsn,
-			AttachStacktrace: true,
-			IgnoreErrors:     []string{"400", "401", "404"},
-		}
-	}
-
-	if err := sentry.Init(*option); err != nil {
-		log.Errorf("ExportSentryOption error: %v", err)
-		return
-	}
-}
-
-func ReportPanic(ctx context.Context, rval interface{}) {
-	hub := hubFromContext(ctx)
-	hub.RecoverWithContext(ctx, rval)
-	return
-}
-
-func hubFromContext(ctx context.Context) *sentry.Hub {
-	hub := sentry.GetHubFromContext(ctx)
-	if hub == nil {
-		hub = sentry.CurrentHub()
-	}
-	return hub
-}
-
-func AddTag(ctx context.Context, k, v string) {
-	hub := sentry.GetHubFromContext(ctx)
-	if hub == nil {
-		return
-	}
-	hub.Scope().SetTag(k, v)
-}
-
-func AddTags(ctx context.Context, tags map[string]string) {
-	hub := sentry.GetHubFromContext(ctx)
-	if hub == nil {
-		return
-	}
-	hub.Scope().SetTags(tags)
-}
-
-func AddExtra(ctx context.Context, k string, v interface{}) {
-	hub := sentry.GetHubFromContext(ctx)
-	if hub == nil {
-		return
-	}
-	hub.Scope().SetExtra(k, v)
-}
-
-func AddExtras(ctx context.Context, extra map[string]interface{}) {
-	hub := sentry.GetHubFromContext(ctx)
-	if hub == nil {
-		return
-	}
-	hub.Scope().SetExtras(extra)
-}

+ 0 - 67
util/xerr/custom_error.go

@@ -1,67 +0,0 @@
-package xerr
-
-import (
-	"encoding/json"
-	"fmt"
-	"strings"
-
-	"kpt-event/util/logger"
-)
-
-// Custom biz custom error
-func Custom(msg string) error {
-	return wrapStack(&CustomError{msg: msg}, 1)
-}
-
-// Customf biz custom error, formats according to a format specifier
-func Customf(format string, a ...interface{}) error {
-	return wrapStack(&CustomError{msg: fmt.Sprintf(format, a...)}, 1)
-}
-
-// CustomError 业务错误代码,不应该返回 500 错误
-// 同时,这个错误不会上传到 NewRelic
-type CustomError struct {
-	msg string
-}
-
-func (e *CustomError) Error() string {
-	return e.msg
-}
-
-func (e *CustomError) CustomError() bool {
-	return true
-}
-
-// IsCustomError 判断是否为业务错误
-func IsCustomError(err error) (error, bool) {
-	type custom interface {
-		CustomError() bool
-	}
-
-	_, ok := Cause(err).(custom)
-	return err, ok
-}
-
-// IgnoreDuplicateEntryError ignore duplicate entry error,
-// return nil if error message contain Duplicate entry,
-// return err in other errors.
-func IgnoreDuplicateEntryError(err error, msg ...interface{}) error {
-	if IsUniqueError(err) {
-		if len(msg) != 0 {
-			bs, _ := json.Marshal(msg)
-			log.Debugf("ignore duplicate record %s", string(bs))
-		}
-
-		return nil
-	}
-
-	return wrapStack(err, 1)
-}
-
-// IsUniqueError 判断是否是 sql unique 错误
-func IsUniqueError(err error) bool {
-	if err == nil {
-		return false
-	}
-	return strings.Contains(err.Error(), "Duplicate entry")
-}

+ 0 - 24
util/xerr/custom_error_test.go

@@ -1,24 +0,0 @@
-package xerr
-
-import (
-	"io"
-	"testing"
-	"time"
-
-	"github.com/stretchr/testify/assert"
-)
-
-func TestCustomError(t *testing.T) {
-	_, got := IsCustomError(Custom("test"))
-	assert.True(t, got)
-
-	_, got = IsCustomError(Customf("test %d", time.Now().Unix()))
-	assert.True(t, got)
-
-	_, got = IsCustomError(io.EOF)
-	assert.False(t, got)
-
-	assert.Error(t, IgnoreDuplicateEntryError(io.EOF))
-	assert.NoError(t, IgnoreDuplicateEntryError(Custom("Duplicate entry UQE-x-y"), "a"))
-	assert.NoError(t, IgnoreDuplicateEntryError(nil))
-}

+ 0 - 281
util/xerr/errors.go

@@ -1,281 +0,0 @@
-// Package xerr provides simple error handling primitives.
-//
-// The traditional error handling idiom in Go is roughly akin to
-//
-//     if err != nil {
-//             return err
-//     }
-//
-// which when applied recursively up the call stack results in error reports
-// without context or debugging information. The errors package allows
-// programmers to add context to the failure path in their code in a way
-// that does not destroy the original value of the error.
-//
-// Adding context to an error
-//
-// The errors.Wrap function returns a new error that adds context to the
-// original error by recording a stack trace at the point Wrap is called,
-// together with the supplied message. For example
-//
-//     _, err := ioutil.ReadAll(r)
-//     if err != nil {
-//             return errors.Wrap(err, "read failed")
-//     }
-//
-// If additional control is required, the errors.WithStack and
-// errors.WithMessage functions destructure errors.Wrap into its component
-// operations: annotating an error with a stack trace and with a message,
-// respectively.
-//
-// Retrieving the cause of an error
-//
-// Using errors.Wrap constructs a stack of errors, adding context to the
-// preceding error. Depending on the nature of the error it may be necessary
-// to reverse the operation of errors.Wrap to retrieve the original error
-// for inspection. Any error value which implements this interface
-//
-//     type causer interface {
-//             Cause() error
-//     }
-//
-// can be inspected by errors.Cause. errors.Cause will recursively retrieve
-// the topmost error that does not implement causer, which is assumed to be
-// the original cause. For example:
-//
-//     switch err := errors.Cause(err).(type) {
-//     case *MyError:
-//             // handle specifically
-//     default:
-//             // unknown error
-//     }
-//
-// Although the causer interface is not exported by this package, it is
-// considered a part of its stable public interface.
-//
-// Formatted printing of errors
-//
-// All error values returned from this package implement fmt.Formatter and can
-// be formatted by the fmt package. The following verbs are supported:
-//
-//     %s    print the error. If the error has a Cause it will be
-//           printed recursively.
-//     %v    see %s
-//     %+v   extended format. Each Frame of the error's StackTrace will
-//           be printed in detail.
-//
-// Retrieving the stack trace of an error or wrapper
-//
-// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
-// invoked. This information can be retrieved with the following interface:
-//
-//     type stackTracer interface {
-//             StackTrace() errors.StackTrace
-//     }
-//
-// The returned errors.StackTrace type is defined as
-//
-//     type StackTrace []Frame
-//
-// The Frame type represents a call site in the stack trace. Frame supports
-// the fmt.Formatter interface that can be used for printing information about
-// the stack trace of this error. For example:
-//
-//     if err, ok := err.(stackTracer); ok {
-//             for _, f := range err.StackTrace() {
-//                     fmt.Printf("%+s:%d", f)
-//             }
-//     }
-//
-// Although the stackTracer interface is not exported by this package, it is
-// considered a part of its stable public interface.
-//
-// See the documentation for Frame.Format for more details.
-package xerr
-
-import (
-	"fmt"
-	"io"
-)
-
-type stackTracer interface {
-	StackTrace() StackTrace
-}
-
-var _ stackTracer = &withStack{}
-var _ stackTracer = &fundamental{}
-
-// New returns an error with the supplied message.
-// New also records the stack trace at the point it was called.
-func New(message string) error {
-	return &fundamental{
-		msg:   message,
-		stack: callers(),
-	}
-}
-
-// Errorf formats according to a format specifier and returns the string
-// as a value that satisfies error.
-// Errorf also records the stack trace at the point it was called.
-func Errorf(format string, args ...interface{}) error {
-	return &fundamental{
-		msg:   fmt.Sprintf(format, args...),
-		stack: callers(),
-	}
-}
-
-// fundamental is an error that has a message and a stack, but no caller.
-type fundamental struct {
-	msg string
-	*stack
-}
-
-func (f *fundamental) Error() string { return f.msg }
-
-func (f *fundamental) Format(s fmt.State, verb rune) {
-	switch verb {
-	case 'v':
-		if s.Flag('+') {
-			io.WriteString(s, f.msg)
-			f.stack.Format(s, verb)
-			return
-		}
-		fallthrough
-	case 's':
-		io.WriteString(s, f.msg)
-	case 'q':
-		fmt.Fprintf(s, "%q", f.msg)
-	}
-}
-
-func (f *fundamental) Stack() []uintptr {
-	return *f.stack
-}
-
-type withStack struct {
-	error
-	*stack
-}
-
-func (w *withStack) Cause() error { return w.error }
-
-func (w *withStack) Format(s fmt.State, verb rune) {
-	switch verb {
-	case 'v':
-		if s.Flag('+') {
-			fmt.Fprintf(s, "%+v", w.Cause())
-			w.stack.Format(s, verb)
-			return
-		}
-		fallthrough
-	case 's':
-		io.WriteString(s, w.Error())
-	case 'q':
-		fmt.Fprintf(s, "%q", w.Error())
-	}
-}
-
-func (w *withStack) Stack() []uintptr {
-	return *w.stack
-}
-
-func (w *withStack) Unwrap() error {
-	return w.error
-}
-
-// Wrapf returns an error annotating err with a stack trace
-// at the point Wrapf is called, and the format specifier.
-// If err is nil, Wrapf returns nil.
-func Wrapf(err error, format string, args ...interface{}) error {
-	if err == nil {
-		return nil
-	}
-	msgErr := &withMessage{
-		cause: err,
-		msg:   fmt.Sprintf(format, args...),
-	}
-	return &withStack{
-		msgErr,
-		callersWithErr(msgErr.Cause()),
-	}
-}
-
-// WithMessagef annotates err with the format specifier.
-// If err is nil, WithMessagef returns nil.
-func WithMessagef(err error, format string, args ...interface{}) error {
-	if err == nil {
-		return nil
-	}
-	return &withMessage{
-		cause: err,
-		msg:   fmt.Sprintf(format, args...),
-	}
-}
-
-type withMessage struct {
-	cause error
-	msg   string
-}
-
-func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() }
-func (w *withMessage) Cause() error  { return w.cause }
-
-func (w *withMessage) Format(s fmt.State, verb rune) {
-	switch verb {
-	case 'v':
-		if s.Flag('+') {
-			fmt.Fprintf(s, "%+v\n", w.Cause())
-			io.WriteString(s, w.msg)
-			return
-		}
-		fallthrough
-	case 's', 'q':
-		io.WriteString(s, w.Error())
-	}
-}
-
-// WithStack annotates err with a stack trace at the point WithStack was called.
-// If err is nil, WithStack returns nil.
-func WithStack(err error) error {
-	return wrapStack(err, 1)
-}
-
-func wrapStack(err error, skip int) error {
-	if err == nil {
-		return nil
-	}
-	if _, ok := err.(stackTracer); ok {
-		return err
-	}
-	if _, ok := err.(interface{ Cause() error }); ok {
-	}
-	return &withStack{
-		err,
-		callersWithSkip(skip + 3),
-	}
-}
-
-// Cause returns the underlying cause of the error, if possible.
-// An error value has a cause if it implements the following
-// interface:
-//
-//     type causer interface {
-//            Cause() error
-//     }
-//
-// If the error does not implement Cause, the original error will
-// be returned. If the error is nil, nil will be returned without further
-// investigation.
-func Cause(err error) error {
-	type causer interface {
-		Cause() error
-	}
-
-	for err != nil {
-		cause, ok := err.(causer)
-		if !ok {
-			break
-		}
-		err = cause.Cause()
-	}
-	return err
-}

+ 0 - 20
util/xerr/errors_test.go

@@ -1,20 +0,0 @@
-package xerr
-
-import (
-	"errors"
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-)
-
-func Test_withStack_Unwrap(t *testing.T) {
-	err := &CustomError{msg: "test error"}
-	stackErr := WithStack(err)
-
-	assert.NotEqual(t, stackErr, err)
-	assert.Equal(t, errors.Unwrap(stackErr), err)
-
-	assert.True(t, errors.Is(stackErr, err))
-	assert.ErrorIs(t, stackErr, err)
-
-}

+ 0 - 158
util/xerr/stack.go

@@ -1,158 +0,0 @@
-package xerr
-
-import (
-	"fmt"
-	"io"
-	"path"
-	"runtime"
-	"strings"
-)
-
-// Frame represents a program counter inside a stack frame.
-type Frame uintptr
-
-// pc returns the program counter for this frame;
-// multiple frames may have the same PC value.
-func (f Frame) pc() uintptr { return uintptr(f) - 1 }
-
-// file returns the full path to the file that contains the
-// function for this Frame's pc.
-func (f Frame) file() string {
-	fn := runtime.FuncForPC(f.pc())
-	if fn == nil {
-		return "unknown"
-	}
-	file, _ := fn.FileLine(f.pc())
-	return file
-}
-
-// line returns the line number of source code of the
-// function for this Frame's pc.
-func (f Frame) line() int {
-	fn := runtime.FuncForPC(f.pc())
-	if fn == nil {
-		return 0
-	}
-	_, line := fn.FileLine(f.pc())
-	return line
-}
-
-// Format formats the frame according to the fmt.Formatter interface.
-//
-//    %s    source file
-//    %d    source line
-//    %n    function name
-//    %v    equivalent to %s:%d
-//
-// Format accepts flags that alter the printing of some verbs, as follows:
-//
-//    %+s   function name and path of source file relative to the compile time
-//          GOPATH separated by \n\t (<funcname>\n\t<path>)
-//    %+v   equivalent to %+s:%d
-func (f Frame) Format(s fmt.State, verb rune) {
-	switch verb {
-	case 's':
-		switch {
-		case s.Flag('+'):
-			pc := f.pc()
-			fn := runtime.FuncForPC(pc)
-			if fn == nil {
-				io.WriteString(s, "unknown")
-			} else {
-				file, _ := fn.FileLine(pc)
-				fmt.Fprintf(s, "%s\n\t%s", fn.Name(), file)
-			}
-		default:
-			io.WriteString(s, path.Base(f.file()))
-		}
-	case 'd':
-		fmt.Fprintf(s, "%d", f.line())
-	case 'n':
-		name := runtime.FuncForPC(f.pc()).Name()
-		io.WriteString(s, funcname(name))
-	case 'v':
-		f.Format(s, 's')
-		io.WriteString(s, ":")
-		f.Format(s, 'd')
-	}
-}
-
-// StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
-type StackTrace []Frame
-
-// Format formats the stack of Frames according to the fmt.Formatter interface.
-//
-//    %s	lists source files for each Frame in the stack
-//    %v	lists the source file and line number for each Frame in the stack
-//
-// Format accepts flags that alter the printing of some verbs, as follows:
-//
-//    %+v   Prints filename, function, and line number for each Frame in the stack.
-func (st StackTrace) Format(s fmt.State, verb rune) {
-	switch verb {
-	case 'v':
-		switch {
-		case s.Flag('+'):
-			for _, f := range st {
-				fmt.Fprintf(s, "\n%+v", f)
-			}
-		case s.Flag('#'):
-			fmt.Fprintf(s, "%#v", []Frame(st))
-		default:
-			fmt.Fprintf(s, "%v", []Frame(st))
-		}
-	case 's':
-		fmt.Fprintf(s, "%s", []Frame(st))
-	}
-}
-
-// stack represents a stack of program counters.
-type stack []uintptr
-
-func (s *stack) Format(st fmt.State, verb rune) {
-	switch verb {
-	case 'v':
-		switch {
-		case st.Flag('+'):
-			for _, pc := range *s {
-				f := Frame(pc)
-				fmt.Fprintf(st, "\n%+v", f)
-			}
-		}
-	}
-}
-
-func (s *stack) StackTrace() StackTrace {
-	f := make([]Frame, len(*s))
-	for i := 0; i < len(f); i++ {
-		f[i] = Frame((*s)[i])
-	}
-	return f
-}
-
-func callers() *stack {
-	return callersWithSkip(4)
-}
-
-func callersWithSkip(skip int) *stack {
-	const depth = 32
-	var pcs [depth]uintptr
-	n := runtime.Callers(skip, pcs[:])
-	var st stack = pcs[0:n]
-	return &st
-}
-
-func callersWithErr(err error) *stack {
-	if stackErr, ok := err.(interface{ Stack() *stack }); ok {
-		return stackErr.Stack()
-	}
-	return callersWithSkip(4)
-}
-
-// funcname removes the path prefix component of a function's name reported by func.Name().
-func funcname(name string) string {
-	i := strings.LastIndex(name, "/")
-	name = name[i+1:]
-	i = strings.Index(name, ".")
-	return name[i+1:]
-}

+ 0 - 44
util/xerr/stack_test.go

@@ -1,44 +0,0 @@
-package xerr
-
-import (
-	"errors"
-	"fmt"
-	"runtime"
-	"testing"
-
-	"github.com/getsentry/sentry-go"
-	"github.com/stretchr/testify/assert"
-	"github.com/stretchr/testify/require"
-)
-
-func TestStackTraceInSentry(t *testing.T) {
-	err := WithStack(errors.New("test error"))
-	stackTrace := sentry.ExtractStacktrace(err)
-	require.NotNil(t, stackTrace)
-	assert.Equal(t, 1, len(stackTrace.Frames))
-}
-
-func TestWithStackRepeat(t *testing.T) {
-	err := WithStack(errors.New("test error"))
-	err = wrapErr(err)
-	_, ok := err.(*withStack)
-	require.True(t, ok)
-}
-
-func TestWrapStack(t *testing.T) {
-	err := wrapStack(nil, 0)
-	require.Nil(t, err, "wrap nil")
-
-	err = wrapStack(errors.New("test error"), 0)
-	require.NotNil(t, err)
-	assert.Equal(t, "test error", err.Error(), "wrap normal error")
-}
-
-func wrapErr(err error) error {
-	return wrapStack(err, 1)
-}
-
-func funcStack(s *stack) string {
-	frame, _ := runtime.CallersFrames(*s).Next()
-	return fmt.Sprintf("pkg.xerr.%s", funcname(frame.Function))
-}

+ 0 - 165
util/xerr/xerr.go

@@ -1,165 +0,0 @@
-package xerr
-
-import (
-	"context"
-	log "kpt-event/util/logger"
-	"kpt-event/util/sentry"
-	"strings"
-
-	"kpt-event/util/runtimeutil"
-)
-
-// 自定义处理过的函数放置在这里
-
-// ReportError 顶层函数需要主动调用这个进行错误日志上报和报警
-func ReportError(ctx context.Context, err error, messages ...string) error {
-	if err == nil {
-		return nil
-	}
-
-	originErr := Cause(err)
-	if originErr == nil {
-		return nil
-	}
-
-	// 忽略业务自定义错误
-	_, ok := originErr.(*CustomError)
-	if ok {
-		return nil
-	}
-
-	e := Wrap(err, messages...)
-
-	// 上报错误到 NewRelic 并且出发报警 🚔
-	// _ = nrutil.NoticeError(getOperation(1), originErr)
-
-	// 上报错误到 Sentry 记录错误
-	sentry.ReportPanic(ctx, e)
-
-	// 打个错误堆栈日志
-	log.Errorf("%+v", e)
-
-	return e
-}
-
-// ReportSentry 顶层函数需要主动调用这个进行错误日志上报
-func ReportSentry(ctx context.Context, err error, messages ...string) {
-	if err == nil {
-		return
-	}
-	// 忽略业务自定义错误
-	_, ok := Cause(err).(*CustomError)
-	if ok {
-		return
-	}
-
-	// 上报错误到 Sentry 记录错误
-	e := Wrap(err, messages...)
-	// sentry.ReportError(ctx, e)
-
-	// 打个错误堆栈日志
-	log.Errorf("%+v", e)
-	return
-}
-
-func getOperation(skip int, operations ...string) string {
-	if len(operations) == 0 {
-		return runtimeutil.CallerFuncName(skip + 1)
-	}
-	return operations[0]
-}
-
-// WithMessage annotates err with a new message.
-// If err is nil, WithMessage returns nil.
-// 如果不传 message,默认会将调用函数写入 message
-func WithMessage(err error, messages ...string) error {
-	if err == nil {
-		return nil
-	}
-
-	return &withMessage{
-		cause: err,
-		msg:   buildMessage(messages...),
-	}
-}
-
-// LogWithWrap returns an error annotating err with a stack trace
-// at the point Wrap is called, and the supplied message.
-// If err is nil, Wrap returns nil.
-// NOTE: 这个默认打错误日志哦
-func WrapWithLog(err error, messages ...string) error {
-	if err == nil {
-		return nil
-	}
-
-	err = &withStack{
-		&withMessage{
-			cause: err,
-			msg:   buildMessage(messages...),
-		},
-		callersWithErr(err),
-	}
-
-	log.Errorf("%+v", err)
-
-	return err
-}
-
-// Wrap returns an error annotating err with a stack trace
-// at the point Wrap is called, and the supplied message.
-// If err is nil, Wrap returns nil.
-func Wrap(err error, messages ...string) error {
-	if err == nil {
-		return nil
-	}
-
-	return &withStack{
-		&withMessage{
-			cause: err,
-			msg:   buildMessage(messages...),
-		},
-		callersWithErr(err),
-	}
-}
-
-func buildMessage(messages ...string) string {
-	if len(messages) == 0 {
-		return runtimeutil.CallerFuncPos(2)
-	}
-	return strings.Join(messages, " ")
-}
-
-// StackWithLog annotates err with a stack trace at the point WithStack was called.
-// If err is nil, WithStack returns nil.
-// NOTE: 这个默认打错误日志哦
-func StackWithLog(err error) error {
-	err = wrapStack(err, 1)
-	if err != nil {
-		log.Errorf("%+s", err)
-	}
-
-	return err
-}
-
-// WithStack annotates err with a stack trace at the point WithStack was called.
-// If err is nil, WithStack returns nil.
-// NOTE: 这个没有打日志哦
-func Stack(err error) error {
-	return wrapStack(err, 1)
-}
-
-// ErrorEqual 判断 err 是否为 errors 某一个错误
-func ErrorEqual(err error, errors ...error) bool {
-	root := Cause(err)
-	if root == nil {
-		return false
-	}
-
-	for _, e := range errors {
-		if root.Error() == e.Error() {
-			return true
-		}
-	}
-
-	return false
-}

+ 0 - 25
util/xerr/xerr_test.go

@@ -1,25 +0,0 @@
-package xerr
-
-import (
-	"io"
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-)
-
-func TestMyWrap(t *testing.T) {
-	assert.Error(t, foo())
-
-	assert.Error(t, Wrap(foo(), "wrap_foo"))
-	assert.Error(t, WrapWithLog(foo(), "wrap_foo_log"))
-
-	assert.Error(t, Wrap(io.EOF))
-	assert.Error(t, WrapWithLog(io.EOF))
-
-	assert.Error(t, WithMessage(foo()))
-	assert.Error(t, WithMessage(foo(), "with message"))
-}
-
-func foo() error {
-	return Wrap(io.EOF, "read file")
-}