-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: hex * style : use gofumpt --------- Co-authored-by: kinggo <[email protected]>
- Loading branch information
1 parent
396233b
commit d391129
Showing
34 changed files
with
3,053 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
*.o | ||
*.a | ||
*.so | ||
_obj | ||
_test | ||
*.[568vq] | ||
[568vq].out | ||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
_testmain.go | ||
*.exe | ||
*.exe~ | ||
*.test | ||
*.prof | ||
*.rar | ||
*.zip | ||
*.gz | ||
*.psd | ||
*.bmd | ||
*.cfg | ||
*.pptx | ||
*.log | ||
*nohup.out | ||
*settings.pyc | ||
*.sublime-project | ||
*.sublime-workspace | ||
!.gitkeep | ||
.DS_Store | ||
/.idea | ||
/.vscode | ||
/output | ||
*.local.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
mod_init: | ||
go mod init cwgo/example/hex | ||
hex: | ||
cwgo server --type RPC --idl idl/hello.thrift --service p.s.m --hex | ||
mod_tidy: | ||
go mod tidy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# CWGO Hex Usage | ||
|
||
## Introduce | ||
The main power of `cwgo hex` is to allow hertz and kitex to listen on the same port and use protocol sniffing to distribute requests to kitex and hertz for processing | ||
## Install | ||
``` | ||
# Go 1.15 and earlier version | ||
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get github.com/cloudwego/cwgo@latest | ||
# Go 1.16 and later version | ||
GOPROXY=https://goproxy.cn/,direct go install github.com/cloudwego/cwgo@latest | ||
``` | ||
## Usage | ||
- init go.mod `go mod init cwgo/example/hex` | ||
- generate code `cwgo server --type RPC --idl idl/hello.thrift --service p.s.m --hex` | ||
- mod tidy `go mod tidy` | ||
|
||
## Test | ||
- `cd /cwgo/example/hex` | ||
- start server: `go run .` | ||
- test rpc: `go run client/main.go` | ||
- `HelloResp({RespBody:[KITEX] hello, hex})` | ||
- test http: `curl 127.0.0.1:8888/hello?name=hex` | ||
- `{"RespBody":"[HERTZ] hello, hex"}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2023 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dal | ||
|
||
import ( | ||
"cwgo/example/hex/biz/dal/mysql" | ||
"cwgo/example/hex/biz/dal/redis" | ||
) | ||
|
||
func Init() { | ||
redis.Init() | ||
mysql.Init() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2023 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package mysql | ||
|
||
import ( | ||
"cwgo/example/hex/conf" | ||
|
||
"gorm.io/driver/mysql" | ||
"gorm.io/gorm" | ||
) | ||
|
||
var ( | ||
DB *gorm.DB | ||
err error | ||
) | ||
|
||
func Init() { | ||
DB, err = gorm.Open(mysql.Open(conf.GetConf().MySQL.DSN), | ||
&gorm.Config{ | ||
PrepareStmt: true, | ||
SkipDefaultTransaction: true, | ||
}, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2023 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package redis | ||
|
||
import ( | ||
"context" | ||
|
||
"cwgo/example/hex/conf" | ||
|
||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
var RedisClient *redis.Client | ||
|
||
func Init() { | ||
RedisClient = redis.NewClient(&redis.Options{ | ||
Addr: conf.GetConf().Redis.Address, | ||
Username: conf.GetConf().Redis.Username, | ||
Password: conf.GetConf().Redis.Password, | ||
DB: conf.GetConf().Redis.DB, | ||
}) | ||
if err := RedisClient.Ping(context.Background()).Err(); err != nil { | ||
panic(err) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2023 CloudWeGo Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package service | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
example "cwgo/example/hex/kitex_gen/hello/example" | ||
|
||
"github.com/cloudwego/kitex/pkg/klog" | ||
) | ||
|
||
type HelloMethodService struct { | ||
ctx context.Context | ||
} // NewHelloMethodService new HelloMethodService | ||
func NewHelloMethodService(ctx context.Context) *HelloMethodService { | ||
return &HelloMethodService{ctx: ctx} | ||
} | ||
|
||
// Run create note info | ||
func (s *HelloMethodService) Run(request *example.HelloReq) (resp *example.HelloResp, err error) { | ||
// Finish your business logic. | ||
resp = new(example.HelloResp) | ||
resp.RespBody = fmt.Sprintf("[KITEX] hello, %s", request.Name) | ||
klog.Infof("[KITEX] hello, %s", request.Name) | ||
return | ||
} |
Oops, something went wrong.