-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6c7965
commit 687d4c6
Showing
16 changed files
with
942 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -19,3 +19,5 @@ | |
|
||
# Go workspace file | ||
go.work | ||
|
||
.idea |
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,13 @@ | ||
FROM golang:1.21 AS builder | ||
WORKDIR $GOPATH/src/packages/app | ||
COPY . . | ||
RUN CGO_ENABLED=0 go build -o /go/myapp main.go | ||
|
||
FROM alpine:latest | ||
WORKDIR /app | ||
COPY config /app/config | ||
COPY --from=builder /go/myapp /app/myapp | ||
RUN chmod +x /app/myapp | ||
EXPOSE 8080 | ||
|
||
CMD ["/app/myapp", "serve"] |
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 @@ | ||
run: | ||
go run main.go serve -c config/example.config.yaml | ||
|
||
dry-build: | ||
go build -o app main.go | ||
rm app |
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 |
---|---|---|
@@ -1 +1,17 @@ | ||
# gin-application-template | ||
# gin-application-template | ||
|
||
## Description | ||
|
||
This is a template for a gin application. | ||
|
||
The following features have already been implemented to simplify the initialization of a new project: | ||
|
||
- [x] Project Structure | ||
- [x] Dockerfile | ||
- [x] Makefile(run, dry-run) | ||
- [x] Gin Server | ||
- [x] Config Management | ||
- [ ] Goreleaser (GitHub Actions) | ||
- [x] API Documentation (Swagger) | ||
- [ ] Database Connection | ||
- [ ] Logging |
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,25 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/leslieleung/gin-application-template/internal/config" | ||
"github.com/leslieleung/gin-application-template/internal/route" | ||
"github.com/spf13/cobra" | ||
"strconv" | ||
) | ||
|
||
var ServeCmd = &cobra.Command{ | ||
Use: "serve", | ||
Run: runServe, | ||
} | ||
|
||
func runServe(cmd *cobra.Command, args []string) { | ||
configPath, _ := cmd.Flags().GetString("config") | ||
cfg := config.New(configPath) | ||
r := route.RegisterRoute() | ||
|
||
r.Run(":" + strconv.Itoa(cfg.GetInt("app.port"))) | ||
} | ||
|
||
func init() { | ||
ServeCmd.Flags().StringP("config", "c", "config/example.config.yaml", "config file path") | ||
} |
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 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/leslieleung/gin-application-template/cmd/app" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "app", | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(app.ServeCmd) | ||
} |
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,2 @@ | ||
app: | ||
port: 8080 |
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,20 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"contact": {} | ||
}, | ||
"paths": { | ||
"/ping": { | ||
"get": { | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"autogenerated" | ||
], | ||
"summary": "A gin example", | ||
"responses": {} | ||
} | ||
} | ||
} | ||
} |
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,12 @@ | ||
info: | ||
contact: {} | ||
paths: | ||
/ping: | ||
get: | ||
produces: | ||
- application/json | ||
responses: {} | ||
summary: A gin example | ||
tags: | ||
- autogenerated | ||
swagger: "2.0" |
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,67 @@ | ||
module github.com/leslieleung/gin-application-template | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/gin-gonic/gin v1.9.1 | ||
github.com/spf13/viper v1.17.0 | ||
github.com/swaggo/files v1.0.1 | ||
github.com/swaggo/gin-swagger v1.6.0 | ||
github.com/swaggo/swag v1.16.2 | ||
) | ||
|
||
require ( | ||
github.com/KyleBanks/depth v1.2.1 // indirect | ||
github.com/PuerkitoBio/purell v1.1.1 // indirect | ||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect | ||
github.com/bytedance/sonic v1.10.2 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect | ||
github.com/chenzhuoyu/iasm v0.9.0 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.19.6 // indirect | ||
github.com/go-openapi/spec v0.20.4 // indirect | ||
github.com/go-openapi/swag v0.19.15 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.15.5 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect | ||
github.com/leodido/go-urn v1.2.4 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mailru/easyjson v0.7.6 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect | ||
github.com/sagikazarmark/locafero v0.3.0 // indirect | ||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect | ||
github.com/sourcegraph/conc v0.3.0 // indirect | ||
github.com/spf13/afero v1.10.0 // indirect | ||
github.com/spf13/cast v1.5.1 // indirect | ||
github.com/spf13/cobra v1.7.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.6.0 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
go.uber.org/atomic v1.9.0 // indirect | ||
go.uber.org/multierr v1.9.0 // indirect | ||
golang.org/x/arch v0.5.0 // indirect | ||
golang.org/x/crypto v0.14.0 // indirect | ||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect | ||
golang.org/x/net v0.16.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
golang.org/x/tools v0.13.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.