-
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
Showing
13 changed files
with
298 additions
and
678 deletions.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.17 | ||
|
||
- name: CI | ||
env: | ||
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} | ||
run: make ci |
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
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,31 @@ | ||
TOOLS_BIN=$(shell pwd)/.tools | ||
COVERALLS_TOKEN?=dev | ||
|
||
install: | ||
go mod download | ||
rm -rf $(TOOLS_BIN) | ||
mkdir -p $(TOOLS_BIN) | ||
GO111MODULE=off GOBIN=$(TOOLS_BIN) go get golang.org/x/tools/cmd/cover | ||
GO111MODULE=off GOBIN=$(TOOLS_BIN) go get github.com/mattn/goveralls | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN) v1.38.0 | ||
|
||
lint: | ||
$(TOOLS_BIN)/golangci-lint -v run ./... | ||
|
||
generate: | ||
go generate -v ./... | ||
|
||
build: | ||
go build -race -v ./... | ||
|
||
tests: | ||
@if [ "$(COVERALLS_TOKEN)" = "dev" ]; then \ | ||
go test -race -v ./... ;\ | ||
else \ | ||
go test -race -v -covermode=atomic -coverprofile=coverage.out ./... ;\ | ||
$(TOOLS_BIN)/goveralls -coverprofile=coverage.out -repotoken $(COVERALLS_TOKEN) ;\ | ||
fi | ||
|
||
pre-commite: generate lint tests | ||
|
||
ci: install build lint tests |
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,2 +1,6 @@ | ||
# goppy | ||
golang framwork | ||
|
||
[![Coverage Status](https://coveralls.io/repos/github/dewep-online/goppy/badge.svg?branch=master)](https://coveralls.io/github/dewep-online/goppy?branch=master) | ||
[![Release](https://img.shields.io/github/release/dewep-online/goppy.svg?style=flat-square)](https://github.com/dewep-online/goppy/releases/latest) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/dewep-online/goppy)](https://goreportcard.com/report/github.com/dewep-online/goppy) | ||
[![CI](https://github.com/dewep-online/goppy/actions/workflows/ci.yml/badge.svg)](https://github.com/dewep-online/goppy/actions/workflows/ci.yml) |
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,9 @@ | ||
env: dev | ||
level: 4 | ||
log: /dev/stdout | ||
|
||
debug: | ||
addr: "127.0.0.1:8081" | ||
|
||
http: | ||
addr: "127.0.0.1:8080" |
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,18 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/dewep-online/goppy" | ||
"github.com/dewep-online/goppy/plugins" | ||
) | ||
|
||
func main() { | ||
|
||
app := goppy.New() | ||
//app.WithConfig("./config.yaml") | ||
app.Plugins( | ||
plugins.WithHTTPDebug(), | ||
plugins.WithHTTP(), | ||
) | ||
app.Run() | ||
|
||
} |
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,18 @@ | ||
module github.com/dewep-online/goppy | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/deweppro/go-app v1.5.2 | ||
github.com/deweppro/go-errors v0.0.4 | ||
github.com/deweppro/go-http v1.4.1 | ||
github.com/deweppro/go-logger v1.3.0 | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b | ||
) | ||
|
||
require ( | ||
github.com/deweppro/go-algorithms v1.1.2 // indirect | ||
github.com/deweppro/go-chan-pool v1.1.2 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
) |
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,32 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/deweppro/go-algorithms v1.1.2 h1:yV/A/M7MjK5Yc2IRdWc3L0nRA3Bz152jdiuVYOGWkwU= | ||
github.com/deweppro/go-algorithms v1.1.2/go.mod h1:zYdfRdlpaXgdT36OgvdjH1qtTZFWEeBi3KUQmWltMPI= | ||
github.com/deweppro/go-app v1.5.2 h1:ZdNhFlmBkEofHSTTb1TGxF/qvYsQ/casyIVe8JVwEeU= | ||
github.com/deweppro/go-app v1.5.2/go.mod h1:i2xQ/YNghOIv90f5841Nj0ZWspDu34QHWfGCcAYjRvc= | ||
github.com/deweppro/go-chan-pool v1.1.2 h1:mm+gvwAFB5NijCiJDSx9RqrB2AWTembzL9Rf6XTv4BI= | ||
github.com/deweppro/go-chan-pool v1.1.2/go.mod h1:6meJsORhraeyvJNPy4hx8xgBNjp2xx3KGB/d5Q5a/I4= | ||
github.com/deweppro/go-errors v0.0.4 h1:TW91LRqHAkUauDJ5lzz73LziANH7mjli1tyvtwzXRCM= | ||
github.com/deweppro/go-errors v0.0.4/go.mod h1:BLsNcxaHh1fjNl/o1TB69JwA8XueSk/Nszkvw4ZwI/I= | ||
github.com/deweppro/go-http v1.4.1 h1:kXh/JTZr7fxWQY5dAh+7QhRkmYxDJ8Ls8O+3Y39a2A8= | ||
github.com/deweppro/go-http v1.4.1/go.mod h1:zta7HINyRd9nmSRtqxw6APOTXwDPBI42G9iZQwqtQVU= | ||
github.com/deweppro/go-logger v1.3.0 h1:KN6RQmb6IoNBxQ7zx7Y1AtptHeL//FRgvQyEF5PrcsE= | ||
github.com/deweppro/go-logger v1.3.0/go.mod h1:jxBBLyHmIvJ4erGUj5qeE6ir36ztyAL1pI+9GymOHVI= | ||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= | ||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= | ||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= | ||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= | ||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,74 @@ | ||
package goppy | ||
|
||
import ( | ||
"github.com/dewep-online/goppy/plugins" | ||
"github.com/deweppro/go-app/application" | ||
"github.com/deweppro/go-errors" | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
) | ||
|
||
type main struct { | ||
app *application.App | ||
config string | ||
plgs []interface{} | ||
cfgs []interface{} | ||
} | ||
|
||
func New() *main { | ||
return &main{ | ||
app: application.New(), | ||
plgs: make([]interface{}, 0, 100), | ||
cfgs: make([]interface{}, 0, 100), | ||
} | ||
} | ||
|
||
func (v *main) WithConfig(filename string) { | ||
v.config = filename | ||
} | ||
|
||
func (v *main) Plugins(args ...plugins.Plugin) { | ||
for _, arg := range args { | ||
if arg.Config != nil { | ||
v.cfgs = append(v.cfgs, arg.Config) | ||
} | ||
if arg.Inject != nil { | ||
v.plgs = append(v.plgs, arg.Inject) | ||
} | ||
if arg.Dependencies != nil { | ||
v.Plugins(arg.Dependencies...) | ||
} | ||
} | ||
} | ||
|
||
func (v *main) Run() { | ||
if len(v.config) == 0 { | ||
v.WithConfig(createTempConfig(v.cfgs...)) | ||
} | ||
|
||
v.app.ConfigFile(v.config, v.cfgs...). | ||
Modules(v.plgs...). | ||
Run() | ||
} | ||
|
||
func createTempConfig(cfgs ...interface{}) string { | ||
filename := "./config.yaml" | ||
if _, err := os.Stat(filename); !errors.Is(err, os.ErrNotExist) { | ||
return filename | ||
} | ||
b, _ := yaml.Marshal(&application.BaseConfig{ | ||
Env: "dev", | ||
Level: 4, | ||
LogFile: "/dev/stdout", | ||
}) | ||
for _, cfg := range cfgs { | ||
if bb, err := yaml.Marshal(cfg); err == nil { | ||
b = append(b, '\n') | ||
b = append(b, bb...) | ||
} | ||
} | ||
if err := os.WriteFile(filename, b, 0755); err != nil { | ||
panic(err) | ||
} | ||
return filename | ||
} |
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,7 @@ | ||
package plugins | ||
|
||
type Plugin struct { | ||
Config interface{} | ||
Inject interface{} | ||
Dependencies []Plugin | ||
} |
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,21 @@ | ||
package plugins | ||
|
||
import ( | ||
"github.com/deweppro/go-http/servers" | ||
"github.com/deweppro/go-http/servers/debug" | ||
"github.com/deweppro/go-logger" | ||
) | ||
|
||
type DebugConfig struct { | ||
Config servers.Config `yaml:"debug"` | ||
} | ||
|
||
func WithHTTPDebug() Plugin { | ||
return Plugin{ | ||
Config: &DebugConfig{}, | ||
Inject: func(conf *DebugConfig, log logger.Logger) *debug.Debug { | ||
return debug.New(conf.Config, log) | ||
}, | ||
Dependencies: nil, | ||
} | ||
} |
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 plugins | ||
|
||
import ( | ||
"github.com/deweppro/go-http/pkg/routes" | ||
"github.com/deweppro/go-http/servers" | ||
"github.com/deweppro/go-http/servers/web" | ||
"github.com/deweppro/go-logger" | ||
) | ||
|
||
type HTTPConfig struct { | ||
Config servers.Config `yaml:"http"` | ||
} | ||
|
||
func WithHTTP() Plugin { | ||
return Plugin{ | ||
Config: &HTTPConfig{}, | ||
Inject: func(conf *HTTPConfig, log logger.Logger) (*web.Server, *routes.Router) { | ||
route := routes.NewRouter() | ||
return web.New(conf.Config, route, log), route | ||
}, | ||
Dependencies: nil, | ||
} | ||
} |