Skip to content

Commit

Permalink
feat: init project
Browse files Browse the repository at this point in the history
  • Loading branch information
dnslin committed Oct 28, 2024
0 parents commit e022e78
Show file tree
Hide file tree
Showing 61 changed files with 4,602 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.idea
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
* text=auto

# Force the following filetypes to have unix eols, so Windows does not break them
*.* text eol=lf

# Windows forced line-endings
/.idea/* text eol=crlf

#
## These files are binary and should be left untouched
#

# (binary is a macro for -text -diff)
*.png binary
133 changes: 133 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
### GoLand+all template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Go template
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

### GoLand template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
### GoLand+iml template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff

# AWS User-specific

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

storage/logs
.idea
*.log
deploy/docker-compose/conf
deploy/docker-compose/data
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Nunu

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.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.PHONY: init
init:
go install github.com/google/wire/cmd/wire@latest
go install github.com/golang/mock/mockgen@latest
go install github.com/swaggo/swag/cmd/swag@latest

.PHONY: bootstrap
bootstrap:
cd ./deploy/docker-compose && docker compose up -d && cd ../../
go run ./cmd/migration
nunu run ./cmd/server

.PHONY: mock
mock:
mockgen -source=internal/service/user.go -destination test/mocks/service/user.go
mockgen -source=internal/repository/user.go -destination test/mocks/repository/user.go
mockgen -source=internal/repository/repository.go -destination test/mocks/repository/repository.go

.PHONY: test
test:
go test -coverpkg=./internal/handler,./internal/service,./internal/repository -coverprofile=./coverage.out ./test/server/...
go tool cover -html=./coverage.out -o coverage.html

.PHONY: build
build:
go build -ldflags="-s -w" -o ./bin/server ./cmd/server

.PHONY: docker
docker:
docker build -f deploy/build/Dockerfile --build-arg APP_RELATIVE_PATH=./cmd/task -t 1.1.1.1:5000/demo-task:v1 .
docker run --rm -i 1.1.1.1:5000/demo-task:v1

.PHONY: swag
swag:
swag init -g cmd/server/main.go -o ./docs --parseDependency
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Nunu — A CLI tool for building Go applications.

Nunu is a scaffolding tool for building Go applications. Its name comes from a game character in League of Legends, a little boy riding on the shoulders of a Yeti. Just like Nunu, this project stands on the shoulders of giants, as it is built upon a combination of popular libraries from the Go ecosystem. This combination allows you to quickly build efficient and reliable applications.

[简体中文介绍](https://github.com/go-nunu/nunu/blob/main/README_zh.md)

![Nunu](https://github.com/go-nunu/nunu/blob/main/.github/assets/banner.png)

## Documentation
* [User Guide](https://github.com/go-nunu/nunu/blob/main/docs/en/guide.md)
* [Architecture](https://github.com/go-nunu/nunu/blob/main/docs/en/architecture.md)
* [Getting Started Tutorial](https://github.com/go-nunu/nunu/blob/main/docs/en/tutorial.md)
* [Unit Testing](https://github.com/go-nunu/nunu/blob/main/docs/en/unit_testing.md)


## License

Nunu is released under the MIT License. For more information, see the [LICENSE](LICENSE) file.
18 changes: 18 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Nunu — A CLI tool for building go aplication.


Nunu是一个基于Golang的应用脚手架,它的名字来自于英雄联盟中的游戏角色,一个骑在雪怪肩膀上的小男孩。和努努一样,该项目也是站在巨人的肩膀上,它是由Golang生态中各种非常流行的库整合而成的,它们的组合可以帮助你快速构建一个高效、可靠的应用程序。

[英文介绍](https://github.com/go-nunu/nunu/blob/main/README.md)

![Nunu](https://github.com/go-nunu/nunu/blob/main/.github/assets/banner.png)

## 文档
* [使用指南](https://github.com/go-nunu/nunu/blob/main/docs/zh/guide.md)
* [分层架构](https://github.com/go-nunu/nunu/blob/main/docs/zh/architecture.md)
* [上手教程](https://github.com/go-nunu/nunu/blob/main/docs/zh/tutorial.md)
* [高效编写单元测试](https://github.com/go-nunu/nunu/blob/main/docs/zh/unit_testing.md)

## 许可证

Nunu是根据MIT许可证发布的。有关更多信息,请参见[LICENSE](LICENSE)文件。
13 changes: 13 additions & 0 deletions api/v1/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package v1

var (
// common errors
ErrSuccess = newError(0, "ok")
ErrBadRequest = newError(400, "Bad Request")
ErrUnauthorized = newError(401, "Unauthorized")
ErrNotFound = newError(404, "Not Found")
ErrInternalServerError = newError(500, "Internal Server Error")

// more biz errors
ErrEmailAlreadyUse = newError(1001, "The email is already in use.")
)
31 changes: 31 additions & 0 deletions api/v1/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package v1

type RegisterRequest struct {
Email string `json:"email" binding:"required,email" example:"[email protected]"`
Password string `json:"password" binding:"required" example:"123456"`
}

type LoginRequest struct {
Email string `json:"email" binding:"required,email" example:"[email protected]"`
Password string `json:"password" binding:"required" example:"123456"`
}
type LoginResponseData struct {
AccessToken string `json:"accessToken"`
}
type LoginResponse struct {
Response
Data LoginResponseData
}

type UpdateProfileRequest struct {
Nickname string `json:"nickname" example:"alan"`
Email string `json:"email" binding:"required,email" example:"[email protected]"`
}
type GetProfileResponseData struct {
UserId string `json:"userId"`
Nickname string `json:"nickname" example:"alan"`
}
type GetProfileResponse struct {
Response
Data GetProfileResponseData
}
51 changes: 51 additions & 0 deletions api/v1/v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package v1

import (
"errors"
"github.com/gin-gonic/gin"
"net/http"
)

type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data"`
}

func HandleSuccess(ctx *gin.Context, data interface{}) {
if data == nil {
data = map[string]interface{}{}
}
resp := Response{Code: errorCodeMap[ErrSuccess], Message: ErrSuccess.Error(), Data: data}
if _, ok := errorCodeMap[ErrSuccess]; !ok {
resp = Response{Code: 0, Message: "", Data: data}
}
ctx.JSON(http.StatusOK, resp)
}

func HandleError(ctx *gin.Context, httpCode int, err error, data interface{}) {
if data == nil {
data = map[string]string{}
}
resp := Response{Code: errorCodeMap[err], Message: err.Error(), Data: data}
if _, ok := errorCodeMap[err]; !ok {
resp = Response{Code: 500, Message: "unknown error", Data: data}
}
ctx.JSON(httpCode, resp)
}

type Error struct {
Code int
Message string
}

var errorCodeMap = map[error]int{}

func newError(code int, msg string) error {
err := errors.New(msg)
errorCodeMap[err] = code
return err
}
func (e Error) Error() string {
return e.Message
}
26 changes: 26 additions & 0 deletions cmd/migration/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"azure-vm-backend/cmd/migration/wire"
"azure-vm-backend/pkg/config"
"azure-vm-backend/pkg/log"
"context"
"flag"
)

func main() {
var envConf = flag.String("conf", "config/local.yml", "config path, eg: -conf ./config/local.yml")
flag.Parse()
conf := config.NewConfig(*envConf)

logger := log.NewLog(conf)

app, cleanup, err := wire.NewWire(conf, logger)
defer cleanup()
if err != nil {
panic(err)
}
if err = app.Run(context.Background()); err != nil {
panic(err)
}
}
Loading

0 comments on commit e022e78

Please sign in to comment.