Skip to content

Commit

Permalink
sail/examples: optimize source code
Browse files Browse the repository at this point in the history
  • Loading branch information
alimy committed May 26, 2024
1 parent e0ca9d3 commit 755bc99
Show file tree
Hide file tree
Showing 58 changed files with 810 additions and 113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
.DS_Store

coverage.out
count.out
Expand Down
2 changes: 2 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ tmp.out

# VS Code
.vscode

examples
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default: run

.PHONY: build
build: fmt
go build -o mir-examples main.go
go build -o examples main.go

.PHONY: build
run: fmt
Expand Down
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/alimy/mir-example/v4
module github.com/alimy/mir/examples/v4

go 1.21

Expand Down
2 changes: 1 addition & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main
import (
"log"

"github.com/alimy/mir-example/v4/servants"
"github.com/alimy/mir/examples/v4/servants"
"github.com/gin-gonic/gin"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/mirc/auto/api/v2/site.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/mirc/auto/api/v3/site.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/mirc/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
. "github.com/alimy/mir/v4/engine"
"github.com/gin-gonic/gin"

_ "github.com/alimy/mir-example/v4/mirc/routes"
_ "github.com/alimy/mir-example/v4/mirc/routes/v1"
_ "github.com/alimy/mir-example/v4/mirc/routes/v2"
_ "github.com/alimy/mir-example/v4/mirc/routes/v3"
_ "github.com/alimy/mir/examples/v4/mirc/routes"
_ "github.com/alimy/mir/examples/v4/mirc/routes/v1"
_ "github.com/alimy/mir/examples/v4/mirc/routes/v2"
_ "github.com/alimy/mir/examples/v4/mirc/routes/v3"
)

//go:generate go run $GOFILE
Expand Down
2 changes: 1 addition & 1 deletion examples/mirc/routes/v3/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package v3

import (
"github.com/alimy/mir-example/v4/model"
"github.com/alimy/mir/examples/v4/model"
. "github.com/alimy/mir/v4"
. "github.com/alimy/mir/v4/engine"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/servants/admin_a.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

import (
api "github.com/alimy/mir-example/v4/mirc/auto/api/v1"
api "github.com/alimy/mir/examples/v4/mirc/auto/api/v1"
)

type adminSrvA struct {
Expand Down
8 changes: 4 additions & 4 deletions examples/servants/servants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
package servants

import (
"github.com/alimy/mir-example/v4/mirc/auto/api"
v1 "github.com/alimy/mir-example/v4/mirc/auto/api/v1"
v2 "github.com/alimy/mir-example/v4/mirc/auto/api/v2"
v3 "github.com/alimy/mir-example/v4/mirc/auto/api/v3"
"github.com/alimy/mir/examples/v4/mirc/auto/api"
v1 "github.com/alimy/mir/examples/v4/mirc/auto/api/v1"
v2 "github.com/alimy/mir/examples/v4/mirc/auto/api/v2"
v3 "github.com/alimy/mir/examples/v4/mirc/auto/api/v3"
"github.com/gin-gonic/gin"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/servants/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

import (
"github.com/alimy/mir-example/v4/mirc/auto/api"
"github.com/alimy/mir/examples/v4/mirc/auto/api"
)

type siteSrv struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/servants/site_a.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

import (
api "github.com/alimy/mir-example/v4/mirc/auto/api/v1"
api "github.com/alimy/mir/examples/v4/mirc/auto/api/v1"
)

type siteSrvA struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/servants/site_b.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

import (
api "github.com/alimy/mir-example/v4/mirc/auto/api/v2"
api "github.com/alimy/mir/examples/v4/mirc/auto/api/v2"
)

type siteSrvB struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/servants/site_c.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

import (
api "github.com/alimy/mir-example/v4/mirc/auto/api/v3"
api "github.com/alimy/mir/examples/v4/mirc/auto/api/v3"
)

type siteSrvC struct {
Expand Down
3 changes: 2 additions & 1 deletion sail/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Binaries for programs and plugins
.DS_Store
*.exe
*.exe~
*.dll
Expand All @@ -24,4 +25,4 @@ tmp.out
# VS Code
.vscode

mir-examples
/examples
22 changes: 22 additions & 0 deletions sail/examples/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# syntax=docker/dockerfile:1

FROM golang:1.22-alpine3.18 AS builder
ENV GOPROXY=https://goproxy.io,direct

WORKDIR /app/examples
ADD . .
RUN --mount=type=cache,target=$GOPATH/pkg,id=examples-gomodcache \
--mount=type=cache,target=/root/.cache/go-build,id=examples-gocache \
go mod download && go build -trimpath -tags 'go_json' -ldflags '-w -s' -o examples

FROM alpine:3.18
WORKDIR /app/examples
COPY --from=builder /app/examples/examples .
COPY --from=builder /app/examples/config.yaml .

VOLUME ["/app/paopao-ce/custom"]
EXPOSE 8080 8081 8082
HEALTHCHECK --interval=5s --timeout=3s --retries=3 CMD ps -ef | grep examples || exit 1

ENTRYPOINT ["/app/examples"]
CMD ["serve"]
4 changes: 2 additions & 2 deletions sail/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BUILD_VERSION := $(shell git describe --tags --always)
BUILD_DATE := $(shell date +'%Y-%m-%d %H:%M:%S %Z')
SHA_SHORT := $(shell git rev-parse --short HEAD)

MOD_NAME = github.com/alimy/mir/sail/mir-example/v4
MOD_NAME = github.com/alimy/mir/sail/examples/v4
LDFLAGS = -X "${MOD_NAME}/internal/conf.version=${BUILD_VERSION}" \
-X "${MOD_NAME}/internal/conf.buildDate=${BUILD_DATE}" \
-X "${MOD_NAME}/internal/conf.commitID=${SHA_SHORT}" \
Expand All @@ -18,7 +18,7 @@ default: serve

.PHONY: build
build: fmt
go build -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o mir-examples main.go
go build -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o examples main.go

.PHONY: build
serve: fmt
Expand Down
113 changes: 113 additions & 0 deletions sail/examples/auto/api/bot/v1/user.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sail/examples/auto/api/v2/site.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sail/examples/auto/api/v3/site.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sail/examples/cmd/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package migrate
import (
"fmt"

"github.com/alimy/mir/sail/mir-example/v4/cmd"
"github.com/alimy/mir/sail/examples/v4/cmd"
"github.com/spf13/cobra"
)

Expand Down
13 changes: 9 additions & 4 deletions sail/examples/cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"os/signal"
"syscall"

"github.com/alimy/mir/sail/mir-example/v4/cmd"
"github.com/alimy/mir/sail/mir-example/v4/internal/service"
"github.com/alimy/mir/sail/examples/v4/cmd"
"github.com/alimy/mir/sail/examples/v4/internal/conf"
"github.com/alimy/mir/sail/examples/v4/internal/service"

"github.com/fatih/color"
"github.com/sourcegraph/conc"
Expand All @@ -28,8 +29,8 @@ var (
func init() {
serveCmd := &cobra.Command{
Use: "serve",
Short: "start mir-example server",
Long: "start mir-example server",
Short: "start sail examples server",
Long: "start sail examples server",
Run: serveRun,
}

Expand All @@ -43,6 +44,10 @@ func serveRun(_cmd *cobra.Command, _args []string) {
// set maxprocs automatic
maxprocs.Set(maxprocs.Logger(log.Printf))

// initial configure
conf.Initial(features, noDefaultFeatures)

// create service runtime
runtime := service.NewRuntime()

// start services
Expand Down
2 changes: 1 addition & 1 deletion sail/examples/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package cmd
import (
"fmt"

"github.com/alimy/mir/sail/mir-example/v4/internal/conf"
"github.com/alimy/mir/sail/examples/v4/internal/conf"
"github.com/spf13/cobra"
)

Expand Down
Loading

0 comments on commit 755bc99

Please sign in to comment.