-
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: add hertz_swagger_gen example (#155)
- Loading branch information
Showing
31 changed files
with
29,096 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
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
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,37 @@ | ||
*.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 | ||
dumped_hertz_remote_config.json | ||
|
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 @@ | ||
// Code generated by hz. DO NOT EDIT. | ||
|
||
hz version: v0.9.1 | ||
handlerDir: "" | ||
modelDir: biz/hertz_gen | ||
routerDir: "" |
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 @@ | ||
init_user: | ||
hz new --model_dir biz/hertz_gen -mod github.com/cloudwego/hertz-examples/bizdemo/hertz_swagger_gen -thrift-plugins=http-swagger -idl idl/user.thrift | ||
|
||
|
||
update_user: | ||
hz update --model_dir biz/hertz_gen -thrift-plugins=http-swagger -idl idl/user.thrift |
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,23 @@ | ||
/* | ||
* Copyright 2024 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 "github.com/cloudwego/hertz-examples/bizdemo/hertz_swagger_gen/biz/dal/mysql" | ||
|
||
func 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,39 @@ | ||
/* | ||
* Copyright 2024 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 ( | ||
"gorm.io/driver/mysql" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/logger" | ||
) | ||
|
||
var dsn = "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local" | ||
|
||
var DB *gorm.DB | ||
|
||
func Init() { | ||
var err error | ||
DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{ | ||
SkipDefaultTransaction: true, | ||
PrepareStmt: true, | ||
Logger: logger.Default.LogMode(logger.Info), | ||
}) | ||
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,48 @@ | ||
/* | ||
* Copyright 2024 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 "github.com/cloudwego/hertz-examples/bizdemo/hertz_swagger_gen/biz/model" | ||
|
||
func CreateUser(users []*model.User) error { | ||
return DB.Create(users).Error | ||
} | ||
|
||
func DeleteUser(userId int64) error { | ||
return DB.Where("id = ?", userId).Delete(&model.User{}).Error | ||
} | ||
|
||
func UpdateUser(user *model.User) error { | ||
return DB.Updates(user).Error | ||
} | ||
|
||
func QueryUser(keyword *string, page, pageSize int64) ([]*model.User, int64, error) { | ||
db := DB.Model(model.User{}) | ||
if keyword != nil && len(*keyword) != 0 { | ||
db = db.Where(DB.Or("name like ?", "%"+*keyword+"%"). | ||
Or("introduce like ?", "%"+*keyword+"%")) | ||
} | ||
var total int64 | ||
if err := db.Count(&total).Error; err != nil { | ||
return nil, 0, err | ||
} | ||
var res []*model.User | ||
if err := db.Limit(int(pageSize)).Offset(int(pageSize * (page - 1))).Find(&res).Error; err != nil { | ||
return nil, 0, err | ||
} | ||
return res, total, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
bizdemo/hertz_swagger_gen/biz/handler/user/user_service.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.