Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
K
kratos-layout
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lizifeng
kratos-layout
Commits
ae2e6415
Commit
ae2e6415
authored
Jun 08, 2022
by
kzkzzzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改全局log
parent
184f42d0
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
19 additions
and
53 deletions
+19
-53
main.go
cmd/server/main.go
+4
-3
wire.go
cmd/server/wire.go
+2
-2
wire_gen.go
cmd/server/wire_gen.go
+0
-35
go.mod
go.mod
+3
-0
go.sum
go.sum
+2
-0
greeter.go
internal/biz/greeter.go
+3
-3
data.go
internal/data/data.go
+2
-2
greeter.go
internal/data/greeter.go
+1
-4
grpc.go
internal/server/grpc.go
+1
-2
http.go
internal/server/http.go
+1
-2
No files found.
cmd/server/main.go
View file @
ae2e6415
...
...
@@ -29,13 +29,12 @@ func init() {
flag
.
StringVar
(
&
flagconf
,
"conf"
,
""
,
"config path, eg: -conf config.yaml"
)
}
func
newApp
(
logger
log
.
Logger
,
hs
*
http
.
Server
,
gs
*
grpc
.
Server
)
*
kratos
.
App
{
func
newApp
(
hs
*
http
.
Server
,
gs
*
grpc
.
Server
)
*
kratos
.
App
{
return
kratos
.
New
(
kratos
.
ID
(
id
),
kratos
.
Name
(
Name
),
kratos
.
Version
(
Version
),
kratos
.
Metadata
(
map
[
string
]
string
{}),
kratos
.
Logger
(
logger
),
kratos
.
Server
(
hs
,
gs
,
...
...
@@ -54,6 +53,8 @@ func main() {
"trace.id"
,
tracing
.
TraceID
(),
"span.id"
,
tracing
.
SpanID
(),
)
log
.
SetLogger
(
logger
)
c
:=
config
.
New
(
config
.
WithSource
(
file
.
NewSource
(
flagconf
),
...
...
@@ -70,7 +71,7 @@ func main() {
panic
(
err
)
}
app
,
cleanup
,
err
:=
wireApp
(
bc
.
Server
,
bc
.
Data
,
logger
)
app
,
cleanup
,
err
:=
wireApp
(
bc
.
Server
,
bc
.
Data
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
cmd/server/wire.go
View file @
ae2e6415
//go:build wireinject
// +build wireinject
// The build tag makes sure the stub is not built in the final build.
...
...
@@ -11,11 +12,10 @@ import (
"github.com/go-kratos/kratos-layout/internal/server"
"github.com/go-kratos/kratos-layout/internal/service"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/log"
"github.com/google/wire"
)
// wireApp init kratos application.
func
wireApp
(
*
conf
.
Server
,
*
conf
.
Data
,
log
.
Logger
)
(
*
kratos
.
App
,
func
(),
error
)
{
func
wireApp
(
*
conf
.
Server
,
*
conf
.
Data
)
(
*
kratos
.
App
,
func
(),
error
)
{
panic
(
wire
.
Build
(
server
.
ProviderSet
,
data
.
ProviderSet
,
biz
.
ProviderSet
,
service
.
ProviderSet
,
newApp
))
}
cmd/server/wire_gen.go
deleted
100644 → 0
View file @
184f42d0
// Code generated by Wire. DO NOT EDIT.
//go:generate go run github.com/google/wire/cmd/wire
//+build !wireinject
package
main
import
(
"github.com/go-kratos/kratos-layout/internal/biz"
"github.com/go-kratos/kratos-layout/internal/conf"
"github.com/go-kratos/kratos-layout/internal/data"
"github.com/go-kratos/kratos-layout/internal/server"
"github.com/go-kratos/kratos-layout/internal/service"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/log"
)
// Injectors from wire.go:
// wireApp init kratos application.
func
wireApp
(
confServer
*
conf
.
Server
,
confData
*
conf
.
Data
,
logger
log
.
Logger
)
(
*
kratos
.
App
,
func
(),
error
)
{
dataData
,
cleanup
,
err
:=
data
.
NewData
(
confData
,
logger
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
greeterRepo
:=
data
.
NewGreeterRepo
(
dataData
,
logger
)
greeterUsecase
:=
biz
.
NewGreeterUsecase
(
greeterRepo
,
logger
)
greeterService
:=
service
.
NewGreeterService
(
greeterUsecase
)
httpServer
:=
server
.
NewHTTPServer
(
confServer
,
greeterService
,
logger
)
grpcServer
:=
server
.
NewGRPCServer
(
confServer
,
greeterService
,
logger
)
app
:=
newApp
(
logger
,
httpServer
,
grpcServer
)
return
app
,
func
()
{
cleanup
()
},
nil
}
go.mod
View file @
ae2e6415
...
...
@@ -16,14 +16,17 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/form/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/subcommands v1.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)
go.sum
View file @
ae2e6415
...
...
@@ -62,6 +62,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/subcommands v1.0.1 h1:/eqq+otEXm5vhfBrbREPCSVQbvofip6kIz+mX5TUH7k=
github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
...
...
@@ -146,6 +147,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
...
...
internal/biz/greeter.go
View file @
ae2e6415
...
...
@@ -34,12 +34,12 @@ type GreeterUsecase struct {
}
// NewGreeterUsecase new a Greeter usecase.
func
NewGreeterUsecase
(
repo
GreeterRepo
,
logger
log
.
Logger
)
*
GreeterUsecase
{
return
&
GreeterUsecase
{
repo
:
repo
,
log
:
log
.
NewHelper
(
logger
)
}
func
NewGreeterUsecase
(
repo
GreeterRepo
)
*
GreeterUsecase
{
return
&
GreeterUsecase
{
repo
:
repo
}
}
// CreateGreeter creates a Greeter, and returns the new Greeter.
func
(
uc
*
GreeterUsecase
)
CreateGreeter
(
ctx
context
.
Context
,
g
*
Greeter
)
(
*
Greeter
,
error
)
{
uc
.
log
.
WithContext
(
ctx
)
.
Infof
(
"CreateGreeter: %v"
,
g
.
Hello
)
log
.
Infof
(
"CreateGreeter: %v"
,
g
.
Hello
)
return
uc
.
repo
.
Save
(
ctx
,
g
)
}
internal/data/data.go
View file @
ae2e6415
...
...
@@ -15,9 +15,9 @@ type Data struct {
}
// NewData .
func
NewData
(
c
*
conf
.
Data
,
logger
log
.
Logger
)
(
*
Data
,
func
(),
error
)
{
func
NewData
(
c
*
conf
.
Data
)
(
*
Data
,
func
(),
error
)
{
cleanup
:=
func
()
{
log
.
NewHelper
(
logger
)
.
Info
(
"closing the data resources"
)
log
.
Info
(
"closing the data resources"
)
}
return
&
Data
{},
cleanup
,
nil
}
internal/data/greeter.go
View file @
ae2e6415
...
...
@@ -4,19 +4,16 @@ import (
"context"
"github.com/go-kratos/kratos-layout/internal/biz"
"github.com/go-kratos/kratos/v2/log"
)
type
greeterRepo
struct
{
data
*
Data
log
*
log
.
Helper
}
// NewGreeterRepo .
func
NewGreeterRepo
(
data
*
Data
,
logger
log
.
Logger
)
biz
.
GreeterRepo
{
func
NewGreeterRepo
(
data
*
Data
)
biz
.
GreeterRepo
{
return
&
greeterRepo
{
data
:
data
,
log
:
log
.
NewHelper
(
logger
),
}
}
...
...
internal/server/grpc.go
View file @
ae2e6415
...
...
@@ -4,13 +4,12 @@ import (
v1
"github.com/go-kratos/kratos-layout/api/helloworld/v1"
"github.com/go-kratos/kratos-layout/internal/conf"
"github.com/go-kratos/kratos-layout/internal/service"
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/middleware/recovery"
"github.com/go-kratos/kratos/v2/transport/grpc"
)
// NewGRPCServer new a gRPC server.
func
NewGRPCServer
(
c
*
conf
.
Server
,
greeter
*
service
.
GreeterService
,
logger
log
.
Logger
)
*
grpc
.
Server
{
func
NewGRPCServer
(
c
*
conf
.
Server
,
greeter
*
service
.
GreeterService
)
*
grpc
.
Server
{
var
opts
=
[]
grpc
.
ServerOption
{
grpc
.
Middleware
(
recovery
.
Recovery
(),
...
...
internal/server/http.go
View file @
ae2e6415
...
...
@@ -4,13 +4,12 @@ import (
v1
"github.com/go-kratos/kratos-layout/api/helloworld/v1"
"github.com/go-kratos/kratos-layout/internal/conf"
"github.com/go-kratos/kratos-layout/internal/service"
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/middleware/recovery"
"github.com/go-kratos/kratos/v2/transport/http"
)
// NewHTTPServer new a HTTP server.
func
NewHTTPServer
(
c
*
conf
.
Server
,
greeter
*
service
.
GreeterService
,
logger
log
.
Logger
)
*
http
.
Server
{
func
NewHTTPServer
(
c
*
conf
.
Server
,
greeter
*
service
.
GreeterService
)
*
http
.
Server
{
var
opts
=
[]
http
.
ServerOption
{
http
.
Middleware
(
recovery
.
Recovery
(),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment