mirror of
https://github.com/go-nunu/nunu.git
synced 2025-09-26 20:31:18 +08:00
feat: Supports Websocket/TCP
This commit is contained in:
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2023 Nunu
|
Copyright (c) 2023-2024 Nunu
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@@ -30,6 +30,7 @@ Nunu is a scaffolding tool for building Go applications. Its name comes from a g
|
|||||||
- **Go-sqlmock**: https://github.com/DATA-DOG/go-sqlmock
|
- **Go-sqlmock**: https://github.com/DATA-DOG/go-sqlmock
|
||||||
- **Gomock**: https://github.com/golang/mock
|
- **Gomock**: https://github.com/golang/mock
|
||||||
- **Swaggo**: https://github.com/swaggo/swag
|
- **Swaggo**: https://github.com/swaggo/swag
|
||||||
|
- **Pitaya**: https://github.com/topfreegames/pitaya
|
||||||
- More...
|
- More...
|
||||||
|
|
||||||
## Key Features
|
## Key Features
|
||||||
|
@@ -30,6 +30,7 @@ Nunu é uma ferramenta de geração de estrutura (scaffolding) para construir ap
|
|||||||
- **Go-sqlmock**: https://github.com/DATA-DOG/go-sqlmock
|
- **Go-sqlmock**: https://github.com/DATA-DOG/go-sqlmock
|
||||||
- **Gomock**: https://github.com/golang/mock
|
- **Gomock**: https://github.com/golang/mock
|
||||||
- **Swaggo**: https://github.com/swaggo/swag
|
- **Swaggo**: https://github.com/swaggo/swag
|
||||||
|
- **Pitaya**: https://github.com/topfreegames/pitaya
|
||||||
- Mais...
|
- Mais...
|
||||||
|
|
||||||
## Funcionalidades Principais
|
## Funcionalidades Principais
|
||||||
|
@@ -30,6 +30,7 @@ Nunu是一个基于Golang的应用脚手架,它的名字来自于英雄联盟
|
|||||||
- **Go-sqlmock**: https://github.com/DATA-DOG/go-sqlmock
|
- **Go-sqlmock**: https://github.com/DATA-DOG/go-sqlmock
|
||||||
- **Gomock**: https://github.com/golang/mock
|
- **Gomock**: https://github.com/golang/mock
|
||||||
- **Swaggo**: https://github.com/swaggo/swag
|
- **Swaggo**: https://github.com/swaggo/swag
|
||||||
|
- **Pitaya**: https://github.com/topfreegames/pitaya
|
||||||
- More...
|
- More...
|
||||||
## 特性
|
## 特性
|
||||||
* **超低学习成本和定制**:Nunu封装了Gopher最熟悉的一些流行库。您可以轻松定制应用程序以满足特定需求。
|
* **超低学习成本和定制**:Nunu封装了Gopher最熟悉的一些流行库。您可以轻松定制应用程序以满足特定需求。
|
||||||
|
@@ -16,7 +16,7 @@ var CmdRoot = &cobra.Command{
|
|||||||
Use: "nunu",
|
Use: "nunu",
|
||||||
Example: "nunu new demo-api",
|
Example: "nunu new demo-api",
|
||||||
Short: "\n _ _ \n| \\ | |_ _ _ __ _ _ \n| \\| | | | | '_ \\| | | |\n| |\\ | |_| | | | | |_| |\n|_| \\_|\\__,_|_| |_|\\__,_| \n \n" + "\x1B[38;2;66;211;146mA\x1B[39m \x1B[38;2;67;209;149mC\x1B[39m\x1B[38;2;68;206;152mL\x1B[39m\x1B[38;2;69;204;155mI\x1B[39m \x1B[38;2;70;201;158mt\x1B[39m\x1B[38;2;71;199;162mo\x1B[39m\x1B[38;2;72;196;165mo\x1B[39m\x1B[38;2;73;194;168ml\x1B[39m \x1B[38;2;74;192;171mf\x1B[39m\x1B[38;2;75;189;174mo\x1B[39m\x1B[38;2;76;187;177mr\x1B[39m \x1B[38;2;77;184;180mb\x1B[39m\x1B[38;2;78;182;183mu\x1B[39m\x1B[38;2;79;179;186mi\x1B[39m\x1B[38;2;80;177;190ml\x1B[39m\x1B[38;2;81;175;193md\x1B[39m\x1B[38;2;82;172;196mi\x1B[39m\x1B[38;2;83;170;199mn\x1B[39m\x1B[38;2;83;167;202mg\x1B[39m \x1B[38;2;84;165;205mg\x1B[39m\x1B[38;2;85;162;208mo\x1B[39m \x1B[38;2;86;160;211ma\x1B[39m\x1B[38;2;87;158;215mp\x1B[39m\x1B[38;2;88;155;218ml\x1B[39m\x1B[38;2;89;153;221mi\x1B[39m\x1B[38;2;90;150;224mc\x1B[39m\x1B[38;2;91;148;227ma\x1B[39m\x1B[38;2;92;145;230mt\x1B[39m\x1B[38;2;93;143;233mi\x1B[39m\x1B[38;2;94;141;236mo\x1B[39m\x1B[38;2;95;138;239mn\x1B[39m\x1B[38;2;96;136;243m.\x1B[39m",
|
Short: "\n _ _ \n| \\ | |_ _ _ __ _ _ \n| \\| | | | | '_ \\| | | |\n| |\\ | |_| | | | | |_| |\n|_| \\_|\\__,_|_| |_|\\__,_| \n \n" + "\x1B[38;2;66;211;146mA\x1B[39m \x1B[38;2;67;209;149mC\x1B[39m\x1B[38;2;68;206;152mL\x1B[39m\x1B[38;2;69;204;155mI\x1B[39m \x1B[38;2;70;201;158mt\x1B[39m\x1B[38;2;71;199;162mo\x1B[39m\x1B[38;2;72;196;165mo\x1B[39m\x1B[38;2;73;194;168ml\x1B[39m \x1B[38;2;74;192;171mf\x1B[39m\x1B[38;2;75;189;174mo\x1B[39m\x1B[38;2;76;187;177mr\x1B[39m \x1B[38;2;77;184;180mb\x1B[39m\x1B[38;2;78;182;183mu\x1B[39m\x1B[38;2;79;179;186mi\x1B[39m\x1B[38;2;80;177;190ml\x1B[39m\x1B[38;2;81;175;193md\x1B[39m\x1B[38;2;82;172;196mi\x1B[39m\x1B[38;2;83;170;199mn\x1B[39m\x1B[38;2;83;167;202mg\x1B[39m \x1B[38;2;84;165;205mg\x1B[39m\x1B[38;2;85;162;208mo\x1B[39m \x1B[38;2;86;160;211ma\x1B[39m\x1B[38;2;87;158;215mp\x1B[39m\x1B[38;2;88;155;218ml\x1B[39m\x1B[38;2;89;153;221mi\x1B[39m\x1B[38;2;90;150;224mc\x1B[39m\x1B[38;2;91;148;227ma\x1B[39m\x1B[38;2;92;145;230mt\x1B[39m\x1B[38;2;93;143;233mi\x1B[39m\x1B[38;2;94;141;236mo\x1B[39m\x1B[38;2;95;138;239mn\x1B[39m\x1B[38;2;96;136;243m.\x1B[39m",
|
||||||
Version: fmt.Sprintf("\n _ _ \n| \\ | |_ _ _ __ _ _ \n| \\| | | | | '_ \\| | | |\n| |\\ | |_| | | | | |_| |\n|_| \\_|\\__,_|_| |_|\\__,_| \n \nNunu %s - Copyright (c) 2023 Nunu\nReleased under the MIT License.\n\n", config.Version),
|
Version: fmt.Sprintf("\n _ _ \n| \\ | |_ _ _ __ _ _ \n| \\| | | | | '_ \\| | | |\n| |\\ | |_| | | | | |_| |\n|_| \\_|\\__,_|_| |_|\\__,_| \n \nNunu %s - Copyright (c) 2023-2024 Nunu\nReleased under the MIT License.\n\n", config.Version),
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version = "1.0.16"
|
Version = "1.1.0"
|
||||||
WireCmd = "github.com/google/wire/cmd/wire@latest"
|
WireCmd = "github.com/google/wire/cmd/wire@latest"
|
||||||
NunuCmd = "github.com/go-nunu/nunu@latest"
|
NunuCmd = "github.com/go-nunu/nunu@latest"
|
||||||
RepoBase = "https://github.com/go-nunu/nunu-layout-base.git"
|
RepoBase = "https://github.com/go-nunu/nunu-layout-base.git"
|
||||||
RepoAdvanced = "https://github.com/go-nunu/nunu-layout-advanced.git"
|
RepoAdvanced = "https://github.com/go-nunu/nunu-layout-advanced.git"
|
||||||
|
RepoChat = "https://github.com/go-nunu/nunu-layout-chat.git"
|
||||||
RunExcludeDir = ".git,.idea,tmp,vendor"
|
RunExcludeDir = ".git,.idea,tmp,vendor"
|
||||||
RunIncludeExt = "go,html,yaml,yml,toml,ini,json,xml,tpl,tmpl"
|
RunIncludeExt = "go,html,yaml,yml,toml,ini,json,xml,tpl,tmpl"
|
||||||
)
|
)
|
||||||
|
@@ -31,17 +31,8 @@ nunu new projectName
|
|||||||
|
|
||||||
This command will create a directory named `projectName` and generate an elegant Golang project structure within it.
|
This command will create a directory named `projectName` and generate an elegant Golang project structure within it.
|
||||||
|
|
||||||
**Accelerated Source in China:**
|
|
||||||
|
|
||||||
By default, `nunu new` fetches from the GitHub source. However, you can also use an accelerated repository in China:
|
> Nunu provides 3 types of layouts:
|
||||||
```
|
|
||||||
// Using the basic template
|
|
||||||
nunu new projectName -r https://gitee.com/go-nunu/nunu-layout-basic.git
|
|
||||||
// Using the advanced template (recommended)
|
|
||||||
nunu new projectName -r https://gitee.com/go-nunu/nunu-layout-advanced.git
|
|
||||||
```
|
|
||||||
|
|
||||||
> Nunu provides two types of layouts:
|
|
||||||
|
|
||||||
* **Basic Layout**
|
* **Basic Layout**
|
||||||
|
|
||||||
@@ -53,6 +44,9 @@ The Basic Layout contains a minimalistic directory structure and is suitable for
|
|||||||
|
|
||||||
The Advanced Layout includes many examples of using Nunu (e.g., db, redis, jwt, cron, migration, etc.), which is suitable for developers to quickly learn and understand the architectural ideas of Nunu.
|
The Advanced Layout includes many examples of using Nunu (e.g., db, redis, jwt, cron, migration, etc.), which is suitable for developers to quickly learn and understand the architectural ideas of Nunu.
|
||||||
|
|
||||||
|
* **Chat Layout**
|
||||||
|
|
||||||
|
Chat Layout is a Nunu based long link project template suitable for scenarios such as instant messaging and game development.
|
||||||
|
|
||||||
## Quick Start with Docker
|
## Quick Start with Docker
|
||||||
|
|
||||||
|
@@ -50,11 +50,14 @@ nunu new projectName -r https://gitee.com/go-nunu/nunu-layout-advanced.git
|
|||||||
// 使用基础模板
|
// 使用基础模板
|
||||||
nunu new projectName -r https://gitee.com/go-nunu/nunu-layout-basic.git
|
nunu new projectName -r https://gitee.com/go-nunu/nunu-layout-basic.git
|
||||||
|
|
||||||
|
// 使用ws/tcp模板(适合即时通信、游戏开发等场景)
|
||||||
|
nunu new projectName -r https://gitee.com/go-nunu/nunu-layout-chat.git
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
> Nunu内置了两种类型的Layout:
|
> Nunu内置了三种类型的Layout:
|
||||||
|
|
||||||
* **基础模板(Basic Layout)**
|
* **基础模板(Basic Layout)**
|
||||||
|
|
||||||
@@ -67,6 +70,9 @@ Basic Layout 包含一个非常精简的架构目录结构,适合非常熟悉N
|
|||||||
|
|
||||||
Advanced Layout 包含了很多Nunu的用法示例( db、redis、 jwt、 cron、 migration等),适合开发者快速学习了解Nunu的架构思想。
|
Advanced Layout 包含了很多Nunu的用法示例( db、redis、 jwt、 cron、 migration等),适合开发者快速学习了解Nunu的架构思想。
|
||||||
|
|
||||||
|
* **即时通信模板(Chat Layout)**
|
||||||
|
|
||||||
|
Chat Layout 是一个基于Nunu的长链接项目模板,适合适合即时通信、游戏开发等场景。
|
||||||
|
|
||||||
|
|
||||||
## 使用docker快速启动项目
|
## 使用docker快速启动项目
|
||||||
|
@@ -111,11 +111,15 @@ func (p *Project) cloneTemplate() (bool, error) {
|
|||||||
Options: []string{
|
Options: []string{
|
||||||
"Advanced",
|
"Advanced",
|
||||||
"Basic",
|
"Basic",
|
||||||
|
"Chat",
|
||||||
},
|
},
|
||||||
Description: func(value string, index int) string {
|
Description: func(value string, index int) string {
|
||||||
if index == 1 {
|
if index == 1 {
|
||||||
return "A basic project structure"
|
return "A basic project structure"
|
||||||
}
|
}
|
||||||
|
if index == 2 {
|
||||||
|
return "A simple chat room containing websocket/tcp"
|
||||||
|
}
|
||||||
return "It has rich functions such as db, jwt, cron, migration, test, etc"
|
return "It has rich functions such as db, jwt, cron, migration, test, etc"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -123,8 +127,10 @@ func (p *Project) cloneTemplate() (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if layout != "Basic" {
|
if layout == "Advanced" {
|
||||||
repo = config.RepoAdvanced
|
repo = config.RepoAdvanced
|
||||||
|
} else if layout == "Chat" {
|
||||||
|
repo = config.RepoChat
|
||||||
}
|
}
|
||||||
err = os.RemoveAll(p.ProjectName)
|
err = os.RemoveAll(p.ProjectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -9,8 +9,10 @@ import (
|
|||||||
type {{ .StructName }}Service interface {
|
type {{ .StructName }}Service interface {
|
||||||
Get{{ .StructName }}(ctx context.Context, id int64) (*model.{{ .StructName }}, error)
|
Get{{ .StructName }}(ctx context.Context, id int64) (*model.{{ .StructName }}, error)
|
||||||
}
|
}
|
||||||
|
func New{{ .StructName }}Service(
|
||||||
func New{{ .StructName }}Service(service *Service, {{ .StructNameLowerFirst }}Repository repository.{{ .StructName }}Repository) {{ .StructName }}Service {
|
service *Service,
|
||||||
|
{{ .StructNameLowerFirst }}Repository repository.{{ .StructName }}Repository,
|
||||||
|
) {{ .StructName }}Service {
|
||||||
return &{{ .StructNameLowerFirst }}Service{
|
return &{{ .StructNameLowerFirst }}Service{
|
||||||
Service: service,
|
Service: service,
|
||||||
{{ .StructNameLowerFirst }}Repository: {{ .StructNameLowerFirst }}Repository,
|
{{ .StructNameLowerFirst }}Repository: {{ .StructNameLowerFirst }}Repository,
|
||||||
|
Reference in New Issue
Block a user