Skip to content

Commit

Permalink
mir: add service package to help start a service. add sail example fo…
Browse files Browse the repository at this point in the history
…r explain how to use mir.
  • Loading branch information
alimy committed Jun 8, 2024
1 parent 755bc99 commit eee4447
Show file tree
Hide file tree
Showing 197 changed files with 147 additions and 301 deletions.
12 changes: 5 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
## mir-examples
just a simple mir's examples for explain how to use mir in your project.
## Examples
Some example for mir.

- [mir-example](mir-example) - simple minimal mir example for explain how to use mir.
- [sail-example](sail-example) - product least mir example for explain how to use mir in production enviroment.

#### Usage
```bash
% make generate
% make run
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Binaries for programs and plugins
.DS_Store
*.exe
*.exe~
*.dll
Expand All @@ -26,3 +25,4 @@ tmp.out
.vscode

/examples
/mir-example
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/mir-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## mir-examples
just a simple mir's examples for explain how to use mir in your project.

#### Usage
```bash
% make generate
% make run
```
4 changes: 2 additions & 2 deletions examples/go.mod → examples/mir-example/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/alimy/mir/examples/v4
module github.com/alimy/mir/mir-example/v4

go 1.21

Expand Down Expand Up @@ -38,4 +38,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/alimy/mir/v4 => ../
replace github.com/alimy/mir/v4 => ../../
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/main.go → examples/mir-example/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/examples/v4/servants"
"github.com/alimy/mir/mir-example/v4/servants"
"github.com/gin-gonic/gin"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

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

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 → examples/mir-example/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/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"
_ "github.com/alimy/mir/mir-example/v4/mirc/routes"
_ "github.com/alimy/mir/mir-example/v4/mirc/routes/v1"
_ "github.com/alimy/mir/mir-example/v4/mirc/routes/v2"
_ "github.com/alimy/mir/mir-example/v4/mirc/routes/v3"
)

//go:generate go run $GOFILE
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package v3

import (
"github.com/alimy/mir/examples/v4/model"
"github.com/alimy/mir/mir-example/v4/model"
. "github.com/alimy/mir/v4"
. "github.com/alimy/mir/v4/engine"
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

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

type adminSrvA struct {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
package servants

import (
"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/alimy/mir/mir-example/v4/mirc/auto/api"
v1 "github.com/alimy/mir/mir-example/v4/mirc/auto/api/v1"
v2 "github.com/alimy/mir/mir-example/v4/mirc/auto/api/v2"
v3 "github.com/alimy/mir/mir-example/v4/mirc/auto/api/v3"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

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

type siteSrv struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

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

type siteSrvA struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

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

type siteSrvB struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package servants

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

type siteSrvC struct {
Expand Down
4 changes: 3 additions & 1 deletion examples/.gitignore → examples/sail-example/.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,5 @@ tmp.out
# VS Code
.vscode

examples
/examples
/sail-example
File renamed without changes.
4 changes: 2 additions & 2 deletions sail/examples/Makefile → examples/sail-example/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/examples/v4
MOD_NAME = github.com/alimy/mir/sail-example/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 examples main.go
go build -trimpath -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o sail-example main.go

.PHONY: build
serve: fmt
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

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

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

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/examples/v4/cmd"
"github.com/alimy/mir/sail-example/v4/cmd"
"github.com/spf13/cobra"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"os/signal"
"syscall"

"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/alimy/mir/sail-example/v4/cmd"
"github.com/alimy/mir/sail-example/v4/internal/conf"
"github.com/alimy/mir/sail-example/v4/internal/service"

"github.com/fatih/color"
"github.com/sourcegraph/conc"
Expand Down
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/examples/v4/internal/conf"
"github.com/alimy/mir/sail-example/v4/internal/conf"
"github.com/spf13/cobra"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 17 additions & 24 deletions sail/examples/go.mod → examples/sail-example/go.mod
Original file line number Diff line number Diff line change
@@ -1,68 +1,61 @@
module github.com/alimy/mir/sail/examples/v4
module github.com/alimy/mir/sail-example/v4

go 1.21

require (
github.com/alimy/mir/sail/v4 v4.2.0
github.com/alimy/mir/v4 v4.2.0
github.com/fatih/color v1.17.0
github.com/gin-gonic/gin v1.10.0
github.com/sourcegraph/conc v0.3.0
github.com/spf13/cobra v1.8.0
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)

require (
github.com/alimy/tryst v0.12.0
github.com/bytedance/sonic v1.11.7 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // 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.20.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // 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.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/automaxprocs v1.5.3
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace (
github.com/alimy/mir/sail/v4 => ../
github.com/alimy/mir/v4 => ../../
)
replace github.com/alimy/mir/v4 => ../../
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func Initial(suite []string, noDefault bool) {
if err != nil {
log.Fatalf("init.setupSetting err: %s", err)
}
// setupMir()
}

func RunMode() string {
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions examples/sail-example/internal/conf/mir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package conf

import (
"github.com/alimy/mir/v4/service"
"github.com/fatih/color"
)

func setupMir() {
service.SetOutput(color.Output)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package bot

import (
api "github.com/alimy/mir/sail/examples/v4/auto/api/bot/v1"
api "github.com/alimy/mir/sail-example/v4/auto/api/bot/v1"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package bot

import (
api "github.com/alimy/mir/sail/examples/v4/auto/api/bot/v1"
"github.com/alimy/mir/sail/examples/v4/internal/servants/base"
api "github.com/alimy/mir/sail-example/v4/auto/api/bot/v1"
"github.com/alimy/mir/sail-example/v4/internal/servants/base"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package docs

import (
"github.com/alimy/mir/sail/examples/v4/docs/openapi"
"github.com/alimy/mir/sail-example/v4/docs/openapi"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package servants

import (
"github.com/alimy/mir/sail/examples/v4/internal/servants/bot"
"github.com/alimy/mir/sail/examples/v4/internal/servants/docs"
"github.com/alimy/mir/sail/examples/v4/internal/servants/web"
"github.com/alimy/mir/sail-example/v4/internal/servants/bot"
"github.com/alimy/mir/sail-example/v4/internal/servants/docs"
"github.com/alimy/mir/sail-example/v4/internal/servants/web"
"github.com/gin-gonic/gin"
)

Expand Down
Loading

0 comments on commit eee4447

Please sign in to comment.