Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@ license:

.PHONY: build
build:
goppy build --arch=amd64
goppy build --arch=amd64 --cgo

.PHONY: tests
tests:
goppy test

.PHONY: pre-commit
pre-commit: install setup license lint build tests
pre-commit: install setup lint license build tests

.PHONY: ci
ci: pre-commit

.PHONY: tidy
tidy:
go mod tidy -v

example-tb: install
cd ./_example/web-server-gen && \
go generate -run goppy ./... && \
go generate -run easyjson ./...
6 changes: 0 additions & 6 deletions _example/web-server-gen/Makefile

This file was deleted.

20 changes: 10 additions & 10 deletions apigen/module/mod-json-rpc-client/build_client_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ func (v Module) buildTransportModel(imp at.ImportSetter, file at.File) []types.T
for _, object := range file.Faces {
for _, method := range object.Methods {

args := map[string][]at.Param{
modelNameRequest: method.InParams,
modelNameResponse: method.OutParams,
args := []argParam{
{tmpl: modelNameRequest, params: method.InParams},
{tmpl: modelNameResponse, params: method.OutParams},
}

for tmpl, params := range args {
for _, arg := range args {

var (
argsOut []types.Token
)

for _, p := range params {
if ignoreModelParam(tmpl, p.Type, p.Pkg) {
for _, p := range arg.params {
if ignoreModelParam(arg.tmpl, p.Type, p.Pkg) {
continue
}

if vals, ok := method.Tags[do.IfElse(tmpl == modelNameRequest, "in.", "out.")+p.Name]; ok && noBodyParam(vals) {
if vals, ok := method.Tags[do.IfElse(arg.tmpl == modelNameRequest, "in.", "out.")+p.Name]; ok && noBodyParam(vals) {
continue
}

Expand All @@ -83,12 +83,12 @@ func (v Module) buildTransportModel(imp at.ImportSetter, file at.File) []types.T

models = append(models,
Line().Comment(jsonGenComment).
Type().ID(fmt.Sprintf(tmpl, object.Name+method.Name)).Struct().Block(argsOut...),
Type().ID(fmt.Sprintf(arg.tmpl, object.Name+method.Name)).Struct().Block(argsOut...),
)

if tmpl == modelNameRequest {
if arg.tmpl == modelNameRequest {
models = append(models, Line().
Func().Bracket(ID(fmt.Sprintf(tmpl, object.Name+method.Name))).
Func().Bracket(ID(fmt.Sprintf(arg.tmpl, object.Name+method.Name))).
ID("Method").Bracket().String().Block(
Return().Text(strings.ToLower(object.Name+"."+method.Name)),
),
Expand Down
11 changes: 10 additions & 1 deletion apigen/module/mod-json-rpc-client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

package mod_json_rpc_client

import "strings"
import (
"strings"

at "go.osspkg.com/goppy/v3/apigen/types"
)

const (
clientName = "%sClient"
Expand Down Expand Up @@ -53,3 +57,8 @@ func noBodyParam(vals []string) bool {
}
return false
}

type argParam struct {
tmpl string
params []at.Param
}
16 changes: 8 additions & 8 deletions apigen/module/mod-json-rpc-server/build_transport_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ func (v Module) buildTransportModel(imp at.ImportSetter, file at.File) []types.T
for _, object := range file.Faces {
for _, method := range object.Methods {

args := map[string][]at.Param{
modelNameReq: method.InParams,
modelNameRes: method.OutParams,
args := []argParam{
{tmpl: modelNameReq, params: method.InParams},
{tmpl: modelNameRes, params: method.OutParams},
}

for tmpl, params := range args {
for _, arg := range args {

var (
argsOut []types.Token
)

for _, p := range params {
if ignoreModelParam(tmpl, p.Type, p.Pkg) {
for _, p := range arg.params {
if ignoreModelParam(arg.tmpl, p.Type, p.Pkg) {
continue
}

if vals, ok := method.Tags[do.IfElse(tmpl == modelNameReq, "in.", "out.")+p.Name]; ok && noBodyParam(vals) {
if vals, ok := method.Tags[do.IfElse(arg.tmpl == modelNameReq, "in.", "out.")+p.Name]; ok && noBodyParam(vals) {
continue
}

Expand All @@ -81,7 +81,7 @@ func (v Module) buildTransportModel(imp at.ImportSetter, file at.File) []types.T
}

models = append(models, Line().Comment(jsonGenComment).
Type().ID(fmt.Sprintf(tmpl, object.Name+method.Name)).Struct().Block(argsOut...),
Type().ID(fmt.Sprintf(arg.tmpl, object.Name+method.Name)).Struct().Block(argsOut...),
)
}
}
Expand Down
11 changes: 10 additions & 1 deletion apigen/module/mod-json-rpc-server/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

package mod_json_rpc_server

import "strings"
import (
"strings"

at "go.osspkg.com/goppy/v3/apigen/types"
)

const (
transportName = "JSONRPC%sTransport"
Expand Down Expand Up @@ -52,3 +56,8 @@ func noBodyParam(vals []string) bool {
}
return false
}

type argParam struct {
tmpl string
params []at.Param
}
10 changes: 5 additions & 5 deletions cmd/goppy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ package main

import (
"go.osspkg.com/goppy/v3/console"
"go.osspkg.com/goppy/v3/env"
"go.osspkg.com/goppy/v3/internal/commands"
"go.osspkg.com/goppy/v3/internal/gen/ormb"
"go.osspkg.com/goppy/v3/internal/global"
)

func main() {
console.ShowDebug(true)
app := console.New("goppy", "Goppy SDK Development Tool")
console.ShowDebug(env.Get("GOPPY_DEBUG", "false") == "true")

global.SetupEnv()

app := console.New("goppy", "Goppy SDK Development Tool")
app.AddCommand(
commands.CmdLicense(),
commands.CmdLint(),
Expand All @@ -27,8 +27,8 @@ func main() {
commands.CmdSetupApp(),
commands.CmdGoSite(),
commands.CmdTB(),
ormb.Command(),
commands.CmdFS(),
commands.CmdORM(),
)

app.Exec()
}
11 changes: 9 additions & 2 deletions console/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package console
import (
"fmt"
"strconv"
"strings"
)

type (
Expand Down Expand Up @@ -175,10 +176,16 @@ func (f *Flags) Bool(name string, usage string) {
name: name,
usage: usage,
call: func(getter ArgGetter) (interface{}, error) {
if getter.Has(name) {
val := getter.Get(name)
if val == nil {
return false, nil
}
switch strings.ToLower(*val) {
case "false", "n", "no", "0":
return false, nil
default:
return true, nil
}
return false, nil
},
})
}
4 changes: 4 additions & 0 deletions console/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ func ShowDebug(ok bool) {
atomic.StoreUint32(&debugLevel, v)
}

func CanShowDebug() bool {
return atomic.LoadUint32(&debugLevel) > 0
}

func Debugf(msg string, args ...interface{}) {
if atomic.LoadUint32(&debugLevel) > 0 {
writeWithColor(colorBlue, "[DEB] "+msg, args)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.

12 changes: 12 additions & 0 deletions examples/internal/rpc-app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SHELL=/bin/bash

build_app:
goppy build --main=./rpc-go-plugin/main.go,./rpc-unix-plugin/main.go,./main.go --cgo


run_app: build_app
./build/app_amd64 --config=config.yaml --config-recovery

check:
curl -iL http://127.0.0.1:8080/call/go-plugin && echo
curl -iL http://127.0.0.1:8080/call/unix-plugin && echo
21 changes: 21 additions & 0 deletions examples/internal/rpc-app/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
http:
- tag: main
addr: 0.0.0.0:8080

rpc:
- name: go-plugin
type: goplugin
path: ./build/rpc-go-plugin_amd64.so
options: {}

- name: unix-plugin
type: unix
path: ./build/rpc-unix-plugin_amd64
options:
config: ./rpc-unix-plugin/config.yaml
config-recovery: true

log:
level: 4
file_path: /dev/stdout
format: string
54 changes: 54 additions & 0 deletions examples/internal/rpc-app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2022-2026 Mikhail Knyazhev <markus621@yandex.com>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

package main

import (
"go.osspkg.com/goppy/v3"
"go.osspkg.com/goppy/v3/rpc"
"go.osspkg.com/goppy/v3/web"
)

func main() {
app := goppy.New("app_name", "v1.0.0", "app description")
app.Plugins(
web.WithServer(),
rpc.WithRPC(),
)
app.Plugins(
NewController,
func(routes web.ServerPool, c *Controller) {
router, ok := routes.Main()
if !ok {
return
}

router.Use(web.ThrottlingMiddleware(100))
router.Get("/call/{app}", c.Call)
},
)
app.Run()
}

type Controller struct {
rpc *rpc.RPC
}

func NewController(rpc *rpc.RPC) *Controller {
return &Controller{rpc: rpc}
}

func (c *Controller) Call(ctx web.Ctx) {
appName, _ := ctx.Param("app").String()

var result any

err := c.rpc.Call(ctx.Context(), appName, "api.ping", struct{}{}, &result)
if err != nil {
ctx.ErrorJSON(400, err)
} else {
ctx.JSON(200, result)
}
}
2 changes: 2 additions & 0 deletions examples/internal/rpc-app/rpc-go-plugin/.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
arch: amd64
mode: plugin
27 changes: 27 additions & 0 deletions examples/internal/rpc-app/rpc-go-plugin/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2022-2026 Mikhail Knyazhev <markus621@yandex.com>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/

package main

import (
"context"
"fmt"
)

func main() {

}

func Start(ctx context.Context, opts map[string]string) error {
return nil
}

func Stop() error {
return nil
}

func Call(ctx context.Context, method string, params, result any) (err error) {
return fmt.Errorf("call ok")
}
2 changes: 2 additions & 0 deletions examples/internal/rpc-app/rpc-unix-plugin/.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
arch: amd64
mode: app
9 changes: 9 additions & 0 deletions examples/internal/rpc-app/rpc-unix-plugin/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
http:
- tag: main
addr: "@env(UNIX_SOCKET_PATH#/tmp/unix.sock)"
network: unix

log:
level: 1
file_path: /dev/stdout
format: string
Loading
Loading