From 9fc911d14619a3f1867ec4b44b464e8c186643ac Mon Sep 17 00:00:00 2001 From: Mikhail Knyazhev Date: Sun, 26 Apr 2026 00:29:02 +0300 Subject: [PATCH 1/3] add rpc plugin support --- Makefile | 5 +- .../{repo_init.go => repo_init_codegen.go} | 5 +- .../{repo_meta.go => repo_meta_codegen.go} | 1 - .../{repo_user.go => repo_user_codegen.go} | 0 _example/rpc-app/Makefile | 12 ++ _example/rpc-app/config.yaml | 21 +++ _example/rpc-app/main.go | 54 ++++++ _example/rpc-app/rpc-go-plugin/.build.yaml | 2 + _example/rpc-app/rpc-go-plugin/main.go | 27 +++ _example/rpc-app/rpc-unix-plugin/.build.yaml | 2 + _example/rpc-app/rpc-unix-plugin/config.yaml | 9 + _example/rpc-app/rpc-unix-plugin/main.go | 56 +++++++ .../transport/jsonrpc_server_api_handler.go | 57 +++++++ .../transport/jsonrpc_server_model.go | 17 ++ .../rpc-unix-plugin/types/interfaces.go | 12 ++ _example/rpc-app/rpc-unix-plugin/types/tb.go | 8 + _example/wasm/.build.yaml | 2 + _example/wasm/main.go | 12 ++ _example/web-server-gen/Makefile | 3 +- .../client/jsonrpc_client_model.go | 10 +- .../client/jsonrpc_client_model_easyjson.go | 1 - .../transport/jsonrpc_server_api_handler.go | 11 +- .../transport/jsonrpc_server_model.go | 12 +- .../jsonrpc_server_model_easyjson.go | 1 - .../transport/jsonrpc_server_post_handler.go | 6 +- .../transport/jsonrpc_server_user_handler.go | 8 +- _example/web-server-gen/types/tb.go | 2 + .../build_client_models.go | 20 +-- apigen/module/mod-json-rpc-client/common.go | 11 +- .../build_transport_models.go | 16 +- apigen/module/mod-json-rpc-server/common.go | 11 +- cmd/goppy/main.go | 1 + console/flags.go | 11 +- goppy.go | 2 +- internal/appconfig/config.go | 11 +- internal/applog/config.go | 14 +- internal/commands/build.go | 156 +++++++++++++----- internal/commands/fileserver.go | 31 ++++ internal/commands/lint.go | 3 +- internal/global/utils.go | 28 ++++ rpc/config.go | 58 +++++++ rpc/goplugin.go | 83 ++++++++++ rpc/plugin_rpc.go | 17 ++ rpc/rpc.go | 75 +++++++++ rpc/types.go | 14 ++ rpc/unixplugin.go | 115 +++++++++++++ web/client/http_client_test.go | 4 +- web/client/http_option.go | 18 +- web/jsonrpc/client.go | 30 ++-- web/jsonrpc/client_option.go | 22 ++- web/jsonrpc/transport.go | 4 +- web/jsonrpc/types.go | 2 +- 52 files changed, 955 insertions(+), 158 deletions(-) rename _example/orm-gen/{repo_init.go => repo_init_codegen.go} (97%) rename _example/orm-gen/{repo_meta.go => repo_meta_codegen.go} (99%) rename _example/orm-gen/{repo_user.go => repo_user_codegen.go} (100%) create mode 100644 _example/rpc-app/Makefile create mode 100755 _example/rpc-app/config.yaml create mode 100644 _example/rpc-app/main.go create mode 100644 _example/rpc-app/rpc-go-plugin/.build.yaml create mode 100644 _example/rpc-app/rpc-go-plugin/main.go create mode 100644 _example/rpc-app/rpc-unix-plugin/.build.yaml create mode 100755 _example/rpc-app/rpc-unix-plugin/config.yaml create mode 100644 _example/rpc-app/rpc-unix-plugin/main.go create mode 100644 _example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go create mode 100644 _example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go create mode 100644 _example/rpc-app/rpc-unix-plugin/types/interfaces.go create mode 100644 _example/rpc-app/rpc-unix-plugin/types/tb.go create mode 100644 _example/wasm/.build.yaml create mode 100644 _example/wasm/main.go create mode 100644 internal/commands/fileserver.go create mode 100644 internal/global/utils.go create mode 100644 rpc/config.go create mode 100644 rpc/goplugin.go create mode 100644 rpc/plugin_rpc.go create mode 100644 rpc/rpc.go create mode 100644 rpc/types.go create mode 100644 rpc/unixplugin.go diff --git a/Makefile b/Makefile index a291772c..a707ee18 100755 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ setup: .PHONY: lint lint: goppy lint + cd _example && goppy lint .PHONY: license license: @@ -18,14 +19,14 @@ 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 diff --git a/_example/orm-gen/repo_init.go b/_example/orm-gen/repo_init_codegen.go similarity index 97% rename from _example/orm-gen/repo_init.go rename to _example/orm-gen/repo_init_codegen.go index 2990f793..a96d0bf2 100755 --- a/_example/orm-gen/repo_init.go +++ b/_example/orm-gen/repo_init_codegen.go @@ -10,9 +10,8 @@ import ( "fmt" "strings" - "go.osspkg.com/ioutils/pool" - "go.osspkg.com/goppy/v3/orm" + "go.osspkg.com/ioutils/pool" ) type Repo struct { @@ -20,7 +19,7 @@ type Repo struct { rtag, wtag string } -func NewRepo(orm orm.ORM) *Repo { +func newRepo(orm orm.ORM) *Repo { return &Repo{ orm: orm, rtag: "slave", diff --git a/_example/orm-gen/repo_meta.go b/_example/orm-gen/repo_meta_codegen.go similarity index 99% rename from _example/orm-gen/repo_meta.go rename to _example/orm-gen/repo_meta_codegen.go index 799d3128..902c7488 100755 --- a/_example/orm-gen/repo_meta.go +++ b/_example/orm-gen/repo_meta_codegen.go @@ -11,7 +11,6 @@ import ( time "time" uuid "github.com/google/uuid" - "go.osspkg.com/goppy/v3/orm" ) diff --git a/_example/orm-gen/repo_user.go b/_example/orm-gen/repo_user_codegen.go similarity index 100% rename from _example/orm-gen/repo_user.go rename to _example/orm-gen/repo_user_codegen.go diff --git a/_example/rpc-app/Makefile b/_example/rpc-app/Makefile new file mode 100644 index 00000000..1102be46 --- /dev/null +++ b/_example/rpc-app/Makefile @@ -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 \ No newline at end of file diff --git a/_example/rpc-app/config.yaml b/_example/rpc-app/config.yaml new file mode 100755 index 00000000..32e3a168 --- /dev/null +++ b/_example/rpc-app/config.yaml @@ -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 \ No newline at end of file diff --git a/_example/rpc-app/main.go b/_example/rpc-app/main.go new file mode 100644 index 00000000..3d788639 --- /dev/null +++ b/_example/rpc-app/main.go @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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) + } +} diff --git a/_example/rpc-app/rpc-go-plugin/.build.yaml b/_example/rpc-app/rpc-go-plugin/.build.yaml new file mode 100644 index 00000000..13308f76 --- /dev/null +++ b/_example/rpc-app/rpc-go-plugin/.build.yaml @@ -0,0 +1,2 @@ +arch: amd64 +mode: plugin diff --git a/_example/rpc-app/rpc-go-plugin/main.go b/_example/rpc-app/rpc-go-plugin/main.go new file mode 100644 index 00000000..5b84702b --- /dev/null +++ b/_example/rpc-app/rpc-go-plugin/main.go @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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") +} diff --git a/_example/rpc-app/rpc-unix-plugin/.build.yaml b/_example/rpc-app/rpc-unix-plugin/.build.yaml new file mode 100644 index 00000000..0daafc59 --- /dev/null +++ b/_example/rpc-app/rpc-unix-plugin/.build.yaml @@ -0,0 +1,2 @@ +arch: amd64 +mode: app diff --git a/_example/rpc-app/rpc-unix-plugin/config.yaml b/_example/rpc-app/rpc-unix-plugin/config.yaml new file mode 100755 index 00000000..d843aef2 --- /dev/null +++ b/_example/rpc-app/rpc-unix-plugin/config.yaml @@ -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 \ No newline at end of file diff --git a/_example/rpc-app/rpc-unix-plugin/main.go b/_example/rpc-app/rpc-unix-plugin/main.go new file mode 100644 index 00000000..2aa417cc --- /dev/null +++ b/_example/rpc-app/rpc-unix-plugin/main.go @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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" + "os" + "time" + + "go.osspkg.com/logx" + + "go.osspkg.com/goppy/v3" + "go.osspkg.com/goppy/v3/_example/rpc-app/rpc-unix-plugin/transport" + "go.osspkg.com/goppy/v3/web" + "go.osspkg.com/goppy/v3/web/jsonrpc" +) + +func main() { + app := goppy.New("app_name", "v1.0.0", "app description") + app.Plugins( + web.WithServer(), + jsonrpc.WithTransport( + jsonrpc.Path("/"), + jsonrpc.Timeout(5*time.Second), + jsonrpc.ErrHandler(func(method string, err error) error { + logx.Error("json-rpc call failed", "method", method, "err", err) + return fmt.Errorf("json-rpc call failed: %w", err) + }), + ), + ) + app.Plugins( + NewController, + func(t jsonrpc.Transport, c *Controller) error { + t.Add(transport.NewJSONRPCApiTransport(c, []string{"main"})) + return nil + }, + ) + app.Run() +} + +type Controller struct{} + +func (c Controller) Ping(ctx context.Context) (pong bool, err error) { + pong = true + go func() { + time.Sleep(time.Second) + os.Exit(0) + }() + return +} + +func NewController() *Controller { return new(Controller) } diff --git a/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go b/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go new file mode 100644 index 00000000..5e927e2d --- /dev/null +++ b/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . All rights reserved. + * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. + */ + +// Code generated by goppy-cli tb. DO NOT EDIT. +package transport + +import ( + context "context" + + web "go.osspkg.com/goppy/v3/web" + jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" + + fmt "fmt" + + stdjson "encoding/json" + + types "go.osspkg.com/goppy/v3/_example/rpc-app/rpc-unix-plugin/types" +) + +type JSONRPCApiTransport struct { + handle types.Api + tags []string +} + +func NewJSONRPCApiTransport(handle types.Api, tags []string) *JSONRPCApiTransport { + return &JSONRPCApiTransport{ + handle: handle, + tags: tags, + } +} + +func (v *JSONRPCApiTransport) RouteTags() []string { + return v.tags +} + +func (v *JSONRPCApiTransport) JSONRPCApiHandlers() map[string]jsonrpc.THandleFunc { + return map[string]jsonrpc.THandleFunc{ + "api.ping": v.CallPing, + } +} + +func (v *JSONRPCApiTransport) CallPing(ctx context.Context, webCtx web.Ctx, param stdjson.RawMessage) (any, error) { + var req jsonrpcApiPingModelRequest + err := stdjson.Unmarshal(param, &req) + if err != nil { + err = fmt.Errorf("invalid request: %w", err) + return nil, err + } + var res jsonrpcApiPingModelResponse + res.Pong, err = v.handle.Ping(ctx) + if err != nil { + return nil, err + } + return res, nil +} diff --git a/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go b/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go new file mode 100644 index 00000000..3890b5f7 --- /dev/null +++ b/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . All rights reserved. + * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. + */ + +// Code generated by goppy-cli tb. DO NOT EDIT. +package transport + +//go:generate easyjson + +//easyjson:json +type jsonrpcApiPingModelRequest struct{} + +//easyjson:json +type jsonrpcApiPingModelResponse struct { + Pong bool `json:"pong"` +} diff --git a/_example/rpc-app/rpc-unix-plugin/types/interfaces.go b/_example/rpc-app/rpc-unix-plugin/types/interfaces.go new file mode 100644 index 00000000..e32680d3 --- /dev/null +++ b/_example/rpc-app/rpc-unix-plugin/types/interfaces.go @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 types + +import "context" + +type Api interface { + Ping(ctx context.Context) (pong bool, err error) +} diff --git a/_example/rpc-app/rpc-unix-plugin/types/tb.go b/_example/rpc-app/rpc-unix-plugin/types/tb.go new file mode 100644 index 00000000..6bcddcf5 --- /dev/null +++ b/_example/rpc-app/rpc-unix-plugin/types/tb.go @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 types + +//go:generate goppy tb --mod=json-rpc-server --out=./../transport diff --git a/_example/wasm/.build.yaml b/_example/wasm/.build.yaml new file mode 100644 index 00000000..c6c0a33a --- /dev/null +++ b/_example/wasm/.build.yaml @@ -0,0 +1,2 @@ +arch: js +mode: wasm diff --git a/_example/wasm/main.go b/_example/wasm/main.go new file mode 100644 index 00000000..70354fae --- /dev/null +++ b/_example/wasm/main.go @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 "fmt" + +func main() { + fmt.Println("wasm app") +} diff --git a/_example/web-server-gen/Makefile b/_example/web-server-gen/Makefile index 166867c3..19b2fc28 100644 --- a/_example/web-server-gen/Makefile +++ b/_example/web-server-gen/Makefile @@ -1,6 +1,7 @@ SHELL=/bin/bash run: - go generate -run easyjson ./transport + go generate -run goppy ./... + go generate -run easyjson ./... go run main.go --config=config.yaml diff --git a/_example/web-server-gen/client/jsonrpc_client_model.go b/_example/web-server-gen/client/jsonrpc_client_model.go index d3b23b95..7e6256b3 100644 --- a/_example/web-server-gen/client/jsonrpc_client_model.go +++ b/_example/web-server-gen/client/jsonrpc_client_model.go @@ -63,11 +63,6 @@ type PostByIDResponse struct { Text bool `json:"text"` } -//easyjson:json -type PostListResponse struct { - Text []types.Text `json:"text,omitempty"` -} - //easyjson:json type PostListRequest struct { UserID int64 `json:"userID"` @@ -76,3 +71,8 @@ type PostListRequest struct { func (PostListRequest) Method() string { return "post.list" } + +//easyjson:json +type PostListResponse struct { + Text []types.Text `json:"text,omitempty"` +} diff --git a/_example/web-server-gen/client/jsonrpc_client_model_easyjson.go b/_example/web-server-gen/client/jsonrpc_client_model_easyjson.go index 5b6ffabd..e6a23c1f 100644 --- a/_example/web-server-gen/client/jsonrpc_client_model_easyjson.go +++ b/_example/web-server-gen/client/jsonrpc_client_model_easyjson.go @@ -8,7 +8,6 @@ import ( easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" jwriter "github.com/mailru/easyjson/jwriter" - types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" ) diff --git a/_example/web-server-gen/transport/jsonrpc_server_api_handler.go b/_example/web-server-gen/transport/jsonrpc_server_api_handler.go index 0bb0f37c..5767e4ea 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_api_handler.go +++ b/_example/web-server-gen/transport/jsonrpc_server_api_handler.go @@ -7,22 +7,21 @@ package transport import ( - time "time" - - types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" - - fmt "fmt" - stdjson "encoding/json" + types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" cast "go.osspkg.com/cast" nethttp "net/http" + time "time" + context "context" + fmt "fmt" + web "go.osspkg.com/goppy/v3/web" ) diff --git a/_example/web-server-gen/transport/jsonrpc_server_model.go b/_example/web-server-gen/transport/jsonrpc_server_model.go index ed508432..edb23164 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_model.go +++ b/_example/web-server-gen/transport/jsonrpc_server_model.go @@ -19,24 +19,24 @@ type jsonrpcApiRootV1ModelResponse struct { Status bool `json:"status"` } -//easyjson:json -type jsonrpcApiAuthV1ModelResponse struct{} - //easyjson:json type jsonrpcApiAuthV1ModelRequest struct { UserName string `json:"userName"` } //easyjson:json -type jsonrpcUserNameV1ModelResponse struct { - Name string `json:"name"` -} +type jsonrpcApiAuthV1ModelResponse struct{} //easyjson:json type jsonrpcUserNameV1ModelRequest struct { UserID int64 `json:"userID"` } +//easyjson:json +type jsonrpcUserNameV1ModelResponse struct { + Name string `json:"name"` +} + //easyjson:json type jsonrpcPostByIDModelRequest struct { ID int64 `json:"ID"` diff --git a/_example/web-server-gen/transport/jsonrpc_server_model_easyjson.go b/_example/web-server-gen/transport/jsonrpc_server_model_easyjson.go index 069e9679..2a0524fc 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_model_easyjson.go +++ b/_example/web-server-gen/transport/jsonrpc_server_model_easyjson.go @@ -8,7 +8,6 @@ import ( easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" jwriter "github.com/mailru/easyjson/jwriter" - types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" ) diff --git a/_example/web-server-gen/transport/jsonrpc_server_post_handler.go b/_example/web-server-gen/transport/jsonrpc_server_post_handler.go index 98a84360..8abeee72 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_post_handler.go +++ b/_example/web-server-gen/transport/jsonrpc_server_post_handler.go @@ -8,13 +8,13 @@ package transport import ( context "context" - stdjson "encoding/json" + fmt "fmt" - web "go.osspkg.com/goppy/v3/web" + stdjson "encoding/json" jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" - fmt "fmt" + web "go.osspkg.com/goppy/v3/web" types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" ) diff --git a/_example/web-server-gen/transport/jsonrpc_server_user_handler.go b/_example/web-server-gen/transport/jsonrpc_server_user_handler.go index 75097691..a1ee423a 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_user_handler.go +++ b/_example/web-server-gen/transport/jsonrpc_server_user_handler.go @@ -7,16 +7,16 @@ package transport import ( - context "context" + stdjson "encoding/json" fmt "fmt" - stdjson "encoding/json" + jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" + + context "context" web "go.osspkg.com/goppy/v3/web" types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" - - jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" ) type JSONRPCUserTransport struct { diff --git a/_example/web-server-gen/types/tb.go b/_example/web-server-gen/types/tb.go index fd316ae7..8860940a 100644 --- a/_example/web-server-gen/types/tb.go +++ b/_example/web-server-gen/types/tb.go @@ -7,3 +7,5 @@ package types //go:generate goppy tb --mod=json-rpc-server --iface=Api,User,Post --out=./../transport //go:generate goppy tb --mod=json-rpc-client --out=./../client +//go:generate easyjson ./../client/jsonrpc_client_model.go +//go:generate easyjson ./../transport/jsonrpc_server_model.go diff --git a/apigen/module/mod-json-rpc-client/build_client_models.go b/apigen/module/mod-json-rpc-client/build_client_models.go index b711fd45..edb57acd 100644 --- a/apigen/module/mod-json-rpc-client/build_client_models.go +++ b/apigen/module/mod-json-rpc-client/build_client_models.go @@ -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 } @@ -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)), ), diff --git a/apigen/module/mod-json-rpc-client/common.go b/apigen/module/mod-json-rpc-client/common.go index c73f89fa..d03eeff7 100644 --- a/apigen/module/mod-json-rpc-client/common.go +++ b/apigen/module/mod-json-rpc-client/common.go @@ -5,7 +5,11 @@ package mod_json_rpc_client -import "strings" +import ( + "strings" + + at "go.osspkg.com/goppy/v3/apigen/types" +) const ( clientName = "%sClient" @@ -53,3 +57,8 @@ func noBodyParam(vals []string) bool { } return false } + +type argParam struct { + tmpl string + params []at.Param +} diff --git a/apigen/module/mod-json-rpc-server/build_transport_models.go b/apigen/module/mod-json-rpc-server/build_transport_models.go index 364261cc..1440d5f0 100644 --- a/apigen/module/mod-json-rpc-server/build_transport_models.go +++ b/apigen/module/mod-json-rpc-server/build_transport_models.go @@ -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 } @@ -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...), ) } } diff --git a/apigen/module/mod-json-rpc-server/common.go b/apigen/module/mod-json-rpc-server/common.go index 114776b8..864cc6f2 100644 --- a/apigen/module/mod-json-rpc-server/common.go +++ b/apigen/module/mod-json-rpc-server/common.go @@ -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" @@ -52,3 +56,8 @@ func noBodyParam(vals []string) bool { } return false } + +type argParam struct { + tmpl string + params []at.Param +} diff --git a/cmd/goppy/main.go b/cmd/goppy/main.go index 194e3c42..e27b49ce 100644 --- a/cmd/goppy/main.go +++ b/cmd/goppy/main.go @@ -27,6 +27,7 @@ func main() { commands.CmdSetupApp(), commands.CmdGoSite(), commands.CmdTB(), + commands.CmdFS(), ormb.Command(), ) diff --git a/console/flags.go b/console/flags.go index 6828d89d..cf7bc1fb 100644 --- a/console/flags.go +++ b/console/flags.go @@ -8,6 +8,7 @@ package console import ( "fmt" "strconv" + "strings" ) type ( @@ -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 }, }) } diff --git a/goppy.go b/goppy.go index 997dd0d4..2013c630 100644 --- a/goppy.go +++ b/goppy.go @@ -142,7 +142,7 @@ func (v *_app) Run() { wg.OnPanic(func(e error) { logx.Error("Run background", "err", e) }) { - conf := &applog.GroupConfig{} + conf := &applog.ConfigGroup{} v.configs = append(v.configs, conf) wg.Background("log writer", func(_ context.Context) { diff --git a/internal/appconfig/config.go b/internal/appconfig/config.go index a6dcfade..dce1a364 100644 --- a/internal/appconfig/config.go +++ b/internal/appconfig/config.go @@ -17,7 +17,6 @@ import ( "go.osspkg.com/ioutils/codec" "go.osspkg.com/ioutils/fs" - "go.osspkg.com/goppy/v3/internal/applog" "go.osspkg.com/goppy/v3/plugins" ) @@ -39,15 +38,7 @@ func Recovery(filename string, configs []any) error { } } - cfg := &applog.GroupConfig{ - Log: applog.Config{ - Level: 4, - FilePath: "/dev/stdout", - Format: "string", - }, - } - - return codec.FileEncoder(filename).Encode(append(configs, cfg)...) + return codec.FileEncoder(filename).Encode(configs...) } type Config struct { diff --git a/internal/applog/config.go b/internal/applog/config.go index 9d7d276f..429fe838 100644 --- a/internal/applog/config.go +++ b/internal/applog/config.go @@ -8,7 +8,7 @@ package applog import "go.osspkg.com/logx" type ( - GroupConfig struct { + ConfigGroup struct { Log Config `yaml:"log"` } @@ -19,12 +19,10 @@ type ( } ) -func Default() *GroupConfig { - return &GroupConfig{ - Log: Config{ - Level: logx.LevelDebug, - FilePath: "/dev/stdout", - Format: "string", - }, +func (v *ConfigGroup) Default() { + v.Log = Config{ + Level: logx.LevelDebug, + FilePath: "/dev/stdout", + Format: "string", } } diff --git a/internal/commands/build.go b/internal/commands/build.go index afe87887..858dbcdb 100644 --- a/internal/commands/build.go +++ b/internal/commands/build.go @@ -6,80 +6,136 @@ package commands import ( + "fmt" + "os" + "path/filepath" "strings" "go.osspkg.com/do" + "go.osspkg.com/ioutils/codec" "go.osspkg.com/ioutils/fs" "go.osspkg.com/goppy/v3/console" - "go.osspkg.com/goppy/v3/internal/global" ) +const buildConfigFileName = ".build.yaml" + +type buildConfig struct { + Mode string `yaml:"mode"` + Arch string `yaml:"arch"` + CGO bool `yaml:"cgo"` +} + func CmdBuild() console.CommandGetter { return console.NewCommand(func(setter console.CommandSetter) { setter.Setup("build", "Building app") setter.Flag(func(flagsSetter console.FlagsSetter) { - flagsSetter.StringVar("arch", "amd64,arm64", "set architecture") - flagsSetter.StringVar("mode", "app", "set application mode (app, plugin)") + flagsSetter.StringVar("arch", "amd64", "set architecture (amd64,arm64,js)") + flagsSetter.StringVar("mode", "app", "set application mode (app,plugin,wasm)") flagsSetter.StringVar("main", "", "set main package for build") + flagsSetter.Bool("cgo", "set CGO_ENABLED=1 for build") }) - setter.ExecFunc(func(_ []string, arch, mode, _main string) { + setter.ExecFunc(func(_ []string, _arch, _mode, _main string, _cgo bool) { console.Infof("--- BUILD ---") pack := make([]string, 0, 10) buildDir := global.GetBuildDir() - mainFiles, err := fs.SearchFiles(fs.CurrentDir(), "main.go") - console.FatalIfErr(err, "detect main.go") + var mainFiles []string + var err error - mb := do.TreatValue(strings.Split(_main, ","), strings.ToLower, strings.TrimSpace) - if len(mb) > 0 { - mainFiles = do.Filter(mainFiles, func(value string, index int) bool { - for _, s := range mb { - if strings.HasSuffix(value, s+"/main.go") { - return true - } - } - return false + if mb := global.SplitFirstString(",", _main); len(mb) > 0 { + mainFiles = do.Filter(mb, func(value string, _ int) bool { + return strings.HasSuffix(value, "/main.go") }) + } else { + mainFiles, err = fs.SearchFiles(fs.CurrentDir(), "main.go") + console.FatalIfErr(err, "detect main.go") } for _, main := range mainFiles { appName := fs.DirName(main) - archList := strings.Split(arch, ",") + switch appName { + case "", "/", ".": + appName = "app" + } - for _, arch = range archList { - pack = append(pack, "rm -rf "+buildDir+"/"+appName+"_"+arch) + console.Infof("build[%s]: %s", appName, main) - chunk := []string{ - "GODEBUG=netdns=9", - "GO111MODULE=on", - "CGO_ENABLED=1", - } + var config buildConfig + configPath := filepath.Join(filepath.Dir(main), buildConfigFileName) + if fs.FileExist(configPath) { + console.Warnf("build config already exists: %s", configPath) + console.FatalIfErr(codec.FileEncoder(configPath).Decode(&config), "build config") + } - switch arch { - case "arm64": - chunk = append(chunk, "GOOS=linux", "GOARCH=arm64") - if fs.FileExist("/usr/bin/aarch64-linux-gnu-gcc") { - chunk = append(chunk, "CC=aarch64-linux-gnu-gcc") + modeList := global.SplitFirstString(",", config.Mode, _mode) + archList := global.SplitFirstString(",", config.Arch, _arch) + cgo := _cgo || config.CGO + + for _, mode := range modeList { + for _, arch := range archList { + + chunk := []string{ + "GODEBUG=netdns=9", + "GO111MODULE=on", } - case "amd64": - chunk = append(chunk, "GOOS=linux", "GOARCH=amd64") - default: - console.Fatalf("possible only arch: amd64, arm64") - } - switch mode { - case "app": - chunk = append(chunk, `go build -ldflags='-s -w' -a -o `+buildDir+"/"+appName+"_"+arch+" "+main) - case "plugin": - chunk = append(chunk, `go build -buildmode=plugin -ldflags='-s -w' -a -o `+buildDir+"/"+appName+"_"+arch+".so "+main) - default: - console.Fatalf("possible only mode: app, plugin") - } + switch arch { + case "arm64": + chunk = append(chunk, "GOOS=linux", "GOARCH=arm64") + if cgo { + if fs.FileExist("/usr/bin/aarch64-linux-gnu-gcc") { + chunk = append(chunk, "CC=aarch64-linux-gnu-gcc") + } else { + console.Warnf("please install aarch64-linux-gnu-gcc") + } + } + + case "amd64": + chunk = append(chunk, "GOOS=linux", "GOARCH=amd64") + + case "js": + chunk = append(chunk, "GOOS=js", "GOARCH=wasm") + mode = "wasm" + + default: + console.Warnf("possible only arch: amd64,arm64,js") + continue + } - pack = append(pack, strings.Join(chunk, " ")) + switch mode { + case "app": + chunk = append(chunk, + "CGO_ENABLED="+do.IfElse(cgo, "1", "0"), + `go build -ldflags='-s -w' -a -o `+buildDir+"/"+appName+"_"+arch+" "+main) + + case "plugin": + chunk = append(chunk, + "CGO_ENABLED="+do.IfElse(cgo, "1", "0"), + `go build -buildmode=plugin -ldflags='-s -w' -a -o `+buildDir+"/"+appName+"_"+arch+".so "+main) + + case "wasm": + chunk = append(chunk, + "CGO_ENABLED=0", + `go build -ldflags='-s -w' -a -o `+buildDir+"/"+appName+".wasm "+main) + pack = append(pack, "cp -rf \"$(go env GOROOT)/lib/wasm/wasm_exec.js\" "+buildDir+"/wasm_exec.js") + console.FatalIfErr( + os.WriteFile( + buildDir+"/"+appName+".html", + []byte(fmt.Sprintf(htmlWasmTmpl, appName)), + 0644), + "write html") + + default: + console.Warnf("possible only mode: app,plugin,wasm") + continue + } + + pack = append(pack, "rm -rf "+buildDir+"/"+appName+"_"+arch) + pack = append(pack, strings.Join(chunk, " ")) + } } } @@ -87,3 +143,19 @@ func CmdBuild() console.CommandGetter { }) }) } + +const htmlWasmTmpl = ` + + + + + + Wasm App + + +` diff --git a/internal/commands/fileserver.go b/internal/commands/fileserver.go new file mode 100644 index 00000000..413d7498 --- /dev/null +++ b/internal/commands/fileserver.go @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 commands + +import ( + "fmt" + "log" + "net/http" + + "go.osspkg.com/ioutils/fs" + + "go.osspkg.com/goppy/v3/console" +) + +func CmdFS() console.CommandGetter { + return console.NewCommand(func(setter console.CommandSetter) { + setter.Setup("fs", "Run file server") + setter.Flag(func(flagsSetter console.FlagsSetter) { + flagsSetter.IntVar("port", 8080, "set port") + }) + setter.ExecFunc(func(port int64) { + serv := http.FileServer(http.Dir(fs.CurrentDir())) + http.Handle("/", serv) + log.Println("FS running on http://localhost:8080") + log.Fatal(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%d", port), nil)) //nolint:gosec + }) + }) +} diff --git a/internal/commands/lint.go b/internal/commands/lint.go index 89080bd1..2f345a08 100644 --- a/internal/commands/lint.go +++ b/internal/commands/lint.go @@ -12,7 +12,6 @@ import ( "go.osspkg.com/ioutils/fs" "go.osspkg.com/goppy/v3/console" - "go.osspkg.com/goppy/v3/internal/global" ) @@ -25,7 +24,7 @@ func CmdLint() console.CommandGetter { updateGoMod() cmds := make([]string, 0, 50) - cmds = append(cmds, "go generate ./...", "gofmt -w -s .", "golangci-lint --version") + cmds = append(cmds, "go generate ./...", "goimports -l -w .", "gofmt -w -s .", "golangci-lint --version") mods, err := fs.SearchFiles(fs.CurrentDir(), "go.mod") console.FatalIfErr(err, "detects go.mod in workspace") for _, mod := range mods { diff --git a/internal/global/utils.go b/internal/global/utils.go new file mode 100644 index 00000000..3d8f3e83 --- /dev/null +++ b/internal/global/utils.go @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 global + +import ( + "strings" + + "go.osspkg.com/do" +) + +func SplitFirstString(div string, oneOf ...string) []string { + var use string + for _, one := range oneOf { + if len(one) > 0 { + use = one + break + } + } + + if len(use) == 0 { + return nil + } + + return do.TreatValue(strings.Split(use, div), strings.ToLower, strings.TrimSpace) +} diff --git a/rpc/config.go b/rpc/config.go new file mode 100644 index 00000000..5940bf02 --- /dev/null +++ b/rpc/config.go @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 rpc + +import ( + "fmt" +) + +type Type string + +const ( + TypeGoPlugin Type = "goplugin" + TypeUnixSocket Type = "unix" +) + +type ConfigGroup struct { + Items []Config `yaml:"rpc"` +} + +type Config struct { + Name string `yaml:"name"` + Type Type `yaml:"type"` + Path string `yaml:"path"` + Options map[string]string `json:"options,omitempty"` +} + +func (v *ConfigGroup) Default() { + if len(v.Items) == 0 { + v.Items = append(v.Items, + Config{ + Name: "go-plugin", + Type: TypeGoPlugin, + Path: "plugin.so", + Options: nil, + }, + Config{ + Name: "unix-plugin", + Type: TypeUnixSocket, + Path: "plugin.bin", + Options: map[string]string{ + "proto": "jsonrpc", + "pid": "/tmp/plugin.pid", + }, + }, + ) + } +} + +func (v *ConfigGroup) Validate() error { + if len(v.Items) == 0 { + return fmt.Errorf("rpc: empty config") + } + + return nil +} diff --git a/rpc/goplugin.go b/rpc/goplugin.go new file mode 100644 index 00000000..8f6413ec --- /dev/null +++ b/rpc/goplugin.go @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 rpc + +import ( + "context" + "fmt" + "plugin" + + "go.osspkg.com/do" + "go.osspkg.com/logx" +) + +type goPlugin struct { + conf Config + funcStart func(ctx context.Context, opts map[string]string) error + funcStop func() error + funcCall func(ctx context.Context, method string, params, result any) error +} + +func newGoPlugin(c Config) (rpcPlugin, error) { + obj := &goPlugin{conf: c} + + p, err := plugin.Open(c.Path) + if err != nil { + return nil, fmt.Errorf("failed to open plugin %s: %w", c.Path, err) + } + + obj.funcStart, err = lookupFunc[func(context.Context, map[string]string) error](p, "Start") + if err != nil { + return nil, fmt.Errorf("failed to lookup function Start in %s: %w", c.Name, err) + } + + obj.funcStop, err = lookupFunc[func() error](p, "Stop") + if err != nil { + return nil, fmt.Errorf("failed to lookup function Stop in %s: %w", c.Name, err) + } + + obj.funcCall, err = lookupFunc[func(context.Context, string, any, any) error](p, "Call") + if err != nil { + return nil, fmt.Errorf("failed to lookup function Call in %s: %w", c.Name, err) + } + + return obj, nil +} + +func (p *goPlugin) Start(ctx context.Context, opts map[string]string) error { + return p.funcStart(ctx, do.JoinMap(p.conf.Options, opts)) +} + +func (p *goPlugin) Stop() error { + return p.funcStop() +} + +func (p *goPlugin) Call(ctx context.Context, method string, params, result any) error { + defer func() { + if err := recover(); err != nil { + logx.Error( + "Go Plugin", + "err", fmt.Errorf("panic: %v", err), + "name", p.conf.Name, + ) + } + }() + return p.funcCall(ctx, method, params, result) +} + +func lookupFunc[T any](p *plugin.Plugin, funcName string) (callback T, err error) { + v, err := p.Lookup(funcName) + if err != nil { + return callback, fmt.Errorf("failed to lookup %s: %w", funcName, err) + } + + var ok bool + if callback, ok = v.(T); !ok { + return callback, fmt.Errorf("plugin does not implement %s", funcName) + } + + return callback, nil +} diff --git a/rpc/plugin_rpc.go b/rpc/plugin_rpc.go new file mode 100644 index 00000000..02195431 --- /dev/null +++ b/rpc/plugin_rpc.go @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 rpc + +import "go.osspkg.com/goppy/v3/plugins" + +func WithRPC() plugins.Kind { + return plugins.Kind{ + Config: &ConfigGroup{}, + Inject: func(conf *ConfigGroup) (*RPC, error) { + return New(conf.Items...), nil + }, + } +} diff --git a/rpc/rpc.go b/rpc/rpc.go new file mode 100644 index 00000000..c2bd649a --- /dev/null +++ b/rpc/rpc.go @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 rpc + +import ( + "context" + "fmt" + + "go.osspkg.com/logx" +) + +type RPC struct { + conf []Config + plugins map[string]rpcPlugin +} + +func New(conf ...Config) *RPC { + return &RPC{ + conf: conf, + plugins: make(map[string]rpcPlugin, len(conf)), + } +} + +func (v *RPC) Up(ctx context.Context) error { + for _, c := range v.conf { + if _, ok := v.plugins[c.Name]; ok { + return fmt.Errorf("plugin %s already exists", c.Name) + } + + var ( + p rpcPlugin + err error + ) + switch c.Type { + case TypeGoPlugin: + p, err = newGoPlugin(c) + case TypeUnixSocket: + p, err = newUnixPlugin(c) + default: + return fmt.Errorf("unknown plugin type: %s (name=%s, path=%s)", c.Type, c.Name, c.Path) + } + + if err != nil { + return fmt.Errorf("failed to init plugin: %w (name=%s, path=%s)", err, c.Name, c.Path) + } + + if err = p.Start(ctx, nil); err != nil { + logx.Error("failed to start rpc plugin", "err", err, "name", c.Name, "path", c.Path) + continue + } + + v.plugins[c.Name] = p + } + return nil +} + +func (v *RPC) Down() error { + for name, p := range v.plugins { + if err := p.Stop(); err != nil { + logx.Error("failed to stop rpc plugin", "err", err, "name", name) + } + } + + return nil +} + +func (v *RPC) Call(ctx context.Context, name string, method string, params, result any) error { + if p, ok := v.plugins[name]; ok { + return p.Call(ctx, method, params, result) + } + return fmt.Errorf("plugin %s not found", name) +} diff --git a/rpc/types.go b/rpc/types.go new file mode 100644 index 00000000..f147e7ed --- /dev/null +++ b/rpc/types.go @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 rpc + +import "context" + +type rpcPlugin interface { + Start(ctx context.Context, opts map[string]string) error + Stop() error + Call(ctx context.Context, method string, params, result any) (err error) +} diff --git a/rpc/unixplugin.go b/rpc/unixplugin.go new file mode 100644 index 00000000..d19fd10c --- /dev/null +++ b/rpc/unixplugin.go @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2022-2026 Mikhail Knyazhev . 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 rpc + +import ( + "context" + "fmt" + "os" + "strings" + + "github.com/google/uuid" + "go.osspkg.com/do" + "go.osspkg.com/ioutils/fs" + "go.osspkg.com/ioutils/shell" + "go.osspkg.com/logx" + "go.osspkg.com/syncing" + "go.osspkg.com/xc" + + "go.osspkg.com/goppy/v3/web/jsonrpc" +) + +type unixPlugin struct { + pidPath string + socketPath string + + serv shell.TShell + cli *jsonrpc.Client + + conf Config + + ctx context.Context + cancel context.CancelFunc + wg syncing.Group +} + +//nolint:unparam +func newUnixPlugin(c Config) (rpcPlugin, error) { + ctx, cancel := context.WithCancel(context.Background()) + obj := &unixPlugin{conf: c, wg: syncing.NewGroup(ctx), ctx: ctx, cancel: cancel} + + obj.pidPath = fmt.Sprintf("/tmp/%s.pid", uuid.New().String()) + obj.socketPath = fmt.Sprintf("/tmp/%s.sock", uuid.New().String()) + + obj.cli = jsonrpc.New("http://rpc.app.local/", + jsonrpc.SetUnixSocket(obj.socketPath), + jsonrpc.SetHeader("X-App-Name", c.Name), + ) + + obj.serv = shell.New() + obj.serv.UseOSEnv(false) + obj.serv.SetDir(fs.CurrentDir()) + obj.serv.SetEnv("UNIX_SOCKET_PATH", obj.socketPath) + + return obj, nil +} + +func (p *unixPlugin) Start(gx context.Context, opts map[string]string) error { + + cmd := []string{p.conf.Path} + for k, v := range do.JoinMap(p.conf.Options, opts) { + cmd = append(cmd, fmt.Sprintf("--%s=%s", k, v)) + } + + p.wg.Background(p.conf.Name, func(bx context.Context) { + ctx, cncl := xc.Join(bx, gx) + defer cncl() + + lw := &logWriter{name: p.conf.Name} + fullCmd := strings.Join(cmd, " ") + + for { + select { + case <-ctx.Done(): + return + default: + os.Remove(p.socketPath) //nolint:errcheck + if err := p.serv.CallContext(ctx, lw, fullCmd); err != nil { + logx.Error( + "Unix Plugin", + "err", err, + "name", p.conf.Name, + ) + } + } + } + + }) + + return nil +} + +func (p *unixPlugin) Stop() error { + p.cancel() + p.wg.Wait() + return nil +} + +func (p *unixPlugin) Call(ctx context.Context, method string, params, result any) error { + in := jsonrpc.ModelAdapter[any]{Data: params} + out := jsonrpc.ModelAdapter[any]{Data: result} + + return p.cli.Call(ctx, method, in, &out) +} + +type logWriter struct { + name string +} + +func (l *logWriter) Write(p []byte) (n int, err error) { + logx.Info("Unix Plugin", "name", l.name, "data", string(p)) + return len(p), nil +} diff --git a/web/client/http_client_test.go b/web/client/http_client_test.go index a4401040..ee2b6b29 100644 --- a/web/client/http_client_test.go +++ b/web/client/http_client_test.go @@ -87,9 +87,7 @@ func TestUnit_HTTPClient(t *testing.T) { time.Sleep(time.Second * 2) cli := client.NewHTTPClient( - client.WithDefaultHeaders(map[string]string{ - "User-Agent": "Mozilla/5.0", - }), + client.WithStaticHeader("User-Agent", "Mozilla/5.0"), client.WithSignatures(map[string]signature.Signature{ "127.0.0.1:12345": signature.NewSHA1("key-1", "1234567890"), }), diff --git a/web/client/http_option.go b/web/client/http_option.go index ab0c051b..0f40f607 100644 --- a/web/client/http_option.go +++ b/web/client/http_option.go @@ -6,6 +6,8 @@ package client import ( + "context" + "net" "net/http" "time" @@ -34,12 +36,18 @@ func WithMaxIdleConns(count int) HTTPOption { } } -func WithDefaultHeaders(h map[string]string) HTTPOption { +func WithUnixSocket(path string) HTTPOption { return func(c *httpCli) { - c.defaultHeaders = make(http.Header, len(h)) - for k, v := range h { - c.defaultHeaders.Set(k, v) - } + c.nativeClient.Transport.(*http.Transport).DialContext = + func(ctx context.Context, _, _ string) (net.Conn, error) { + return c.netDialer.Dial("unix", path) + } + } +} + +func WithStaticHeader(key, value string) HTTPOption { + return func(c *httpCli) { + c.defaultHeaders.Set(key, value) } } diff --git a/web/jsonrpc/client.go b/web/jsonrpc/client.go index 9a554eea..4bfe2b71 100644 --- a/web/jsonrpc/client.go +++ b/web/jsonrpc/client.go @@ -20,37 +20,27 @@ import ( type Client struct { address string cli client.HTTPClient - opts *cliopts + genID func() string } func New(address string, opts ...Opt) *Client { cliOpts := &cliopts{ - timeout: 0, - genID: uuid.NewString, - defaultHeaders: make(map[string]string, 2), - contextHeaders: make(map[string]any, 2), + genID: uuid.NewString, + httpopts: []client.HTTPOption{ + client.WithComparisonType( + comparison.JSON{Force: true}, + ), + }, } for _, opt := range opts { opt(cliOpts) } - httpcliopts := []client.HTTPOption{ - client.WithComparisonType( - comparison.JSON{Force: true}, - ), - client.WithDefaultHeaders(cliOpts.defaultHeaders), - client.WithTimeouts(cliOpts.timeout, cliOpts.keepalive), - } - - for k, v := range cliOpts.contextHeaders { - httpcliopts = append(httpcliopts, client.WithContextHeaderValue(k, v)) - } - return &Client{ address: address, - cli: client.NewHTTPClient(httpcliopts...), - opts: cliOpts, + cli: client.NewHTTPClient(cliOpts.httpopts...), + genID: cliOpts.genID, } } @@ -91,7 +81,7 @@ func (c *Client) BulkCall(ctx context.Context, bulk ...*Chunk) error { ids := make(map[string]*Chunk, len(bulk)) for _, ch := range bulk { - id := c.opts.genID() + id := c.genID() ids[id] = ch *req = append(*req, requestAny{ Id: id, diff --git a/web/jsonrpc/client_option.go b/web/jsonrpc/client_option.go index 94671a45..df276f43 100644 --- a/web/jsonrpc/client_option.go +++ b/web/jsonrpc/client_option.go @@ -7,16 +7,15 @@ package jsonrpc import ( "time" + + "go.osspkg.com/goppy/v3/web/client" ) type Opt func(o *cliopts) type cliopts struct { - timeout time.Duration - keepalive time.Duration - genID func() string - defaultHeaders map[string]string - contextHeaders map[string]any + genID func() string + httpopts []client.HTTPOption } func SetGenID(arg func() string) Opt { @@ -30,19 +29,24 @@ func SetGenID(arg func() string) Opt { func SetTimeout(timeout, keepalive time.Duration) Opt { return func(o *cliopts) { - o.timeout = max(timeout, time.Second) - o.keepalive = max(keepalive, time.Second) + o.httpopts = append(o.httpopts, client.WithTimeouts(timeout, keepalive)) } } func SetHeader(key, value string) Opt { return func(o *cliopts) { - o.defaultHeaders[key] = value + o.httpopts = append(o.httpopts, client.WithStaticHeader(key, value)) } } func SetContextHeader(header string, key any) Opt { return func(o *cliopts) { - o.contextHeaders[header] = key + o.httpopts = append(o.httpopts, client.WithContextHeaderValue(header, key)) + } +} + +func SetUnixSocket(path string) Opt { + return func(o *cliopts) { + o.httpopts = append(o.httpopts, client.WithUnixSocket(path)) } } diff --git a/web/jsonrpc/transport.go b/web/jsonrpc/transport.go index 81eb9b72..e08a0bca 100644 --- a/web/jsonrpc/transport.go +++ b/web/jsonrpc/transport.go @@ -123,13 +123,13 @@ func (v *service) Handle(resolve *syncing.Map[string, THandleFunc]) func(wc web. result, err := handler(ctx, wc, item.Params) if err != nil { - out.Error = errorConvert(v.opt.errHandler(method, err)) + out.Error = errConvert(v.opt.errHandler(method, err)) } else { out.Result = result } } else { - out.Error = errorConvert(ErrUnsupportedMethod) + out.Error = errConvert(ErrUnsupportedMethod) } res.Append(out) diff --git a/web/jsonrpc/types.go b/web/jsonrpc/types.go index 8c046a16..6fbf41a6 100644 --- a/web/jsonrpc/types.go +++ b/web/jsonrpc/types.go @@ -82,7 +82,7 @@ func (e *errResponse) Error() string { return fmt.Sprintf("#%d %v", e.Code, e.Message) } -func errorConvert(e error) *errResponse { +func errConvert(e error) *errResponse { if e == nil { return nil } From 1559ad56017015562a0052139c545c37ae6d078b Mon Sep 17 00:00:00 2001 From: Mikhail Knyazhev Date: Sun, 26 Apr 2026 01:12:31 +0300 Subject: [PATCH 2/3] add rpc plugin support --- Makefile | 6 - cmd/goppy/main.go | 9 +- console/io.go | 4 + .../internal}/basic/Makefile | 0 .../internal}/basic/config.yaml | 0 {_example => examples/internal}/basic/main.go | 0 .../internal}/database/Makefile | 0 .../internal}/database/config.yaml | 0 .../internal}/database/main.go | 0 .../database/migrations/0001_data.sql | 0 .../internal}/demo-console/Makefile | 0 .../internal}/demo-console/main.go | 0 .../internal}/dns-server/Makefile | 0 .../internal}/dns-server/config.yaml | 0 .../internal}/dns-server/main.go | 0 .../internal}/geoip/Makefile | 0 .../internal}/geoip/config.yaml | 0 {_example => examples/internal}/geoip/main.go | 0 .../internal}/oauth/Makefile | 0 .../internal}/oauth/config.yaml | 0 {_example => examples/internal}/oauth/main.go | 0 .../internal}/orm-gen/001000_users_table.sql | 0 .../internal}/orm-gen/001001_meta_table.sql | 0 .../internal}/orm-gen/empty.go | 0 .../internal}/orm-gen/model.go | 0 .../internal}/orm-gen/repo_init_codegen.go | 3 +- .../internal}/orm-gen/repo_meta_codegen.go | 1 + .../internal}/orm-gen/repo_user_codegen.go | 0 .../internal}/rpc-app/Makefile | 0 .../internal}/rpc-app/config.yaml | 0 .../internal}/rpc-app/main.go | 0 .../rpc-app/rpc-go-plugin/.build.yaml | 0 .../internal}/rpc-app/rpc-go-plugin/main.go | 0 .../rpc-app/rpc-unix-plugin/.build.yaml | 0 .../rpc-app/rpc-unix-plugin/config.yaml | 0 .../internal}/rpc-app/rpc-unix-plugin/main.go | 3 +- .../transport/jsonrpc_server_api_handler.go | 10 +- .../transport/jsonrpc_server_model.go | 0 .../jsonrpc_server_model_easyjson.go | 139 ++++++++++++++++++ .../rpc-unix-plugin/types/interfaces.go | 0 .../rpc-app/rpc-unix-plugin/types/tb.go | 1 + .../internal}/wasm/.build.yaml | 0 {_example => examples/internal}/wasm/main.go | 0 .../internal}/web-server-gen/Makefile | 0 .../client/jsonrpc_client_api_handler.go | 0 .../client/jsonrpc_client_model.go | 2 +- .../client/jsonrpc_client_model_easyjson.go | 131 +++++++++-------- .../client/jsonrpc_client_post_handler.go | 0 .../client/jsonrpc_client_user_handler.go | 0 .../internal}/web-server-gen/config.yaml | 0 .../internal}/web-server-gen/main.go | 4 +- .../internal}/web-server-gen/test.http | 0 .../transport/jsonrpc_server_api_handler.go | 10 +- .../transport/jsonrpc_server_model.go | 2 +- .../jsonrpc_server_model_easyjson.go | 131 +++++++++-------- .../transport/jsonrpc_server_post_handler.go | 10 +- .../transport/jsonrpc_server_user_handler.go | 9 +- .../web-server-gen/types/interfaces1.go | 0 .../web-server-gen/types/interfaces2.go | 0 .../internal}/web-server-gen/types/tb.go | 0 .../internal}/ws-client/Makefile | 0 .../internal}/ws-client/config.yaml | 0 .../internal}/ws-client/main.go | 3 +- .../internal}/ws-server/Makefile | 0 .../internal}/ws-server/config.yaml | 0 .../internal}/ws-server/index.html | 0 .../internal}/ws-server/main.go | 1 + internal/commands/build.go | 2 +- internal/commands/gosite.go | 3 +- internal/commands/license.go | 2 +- internal/commands/lint.go | 2 +- .../{gen/ormb/command.go => commands/orm.go} | 15 +- internal/commands/setup.go | 5 +- internal/commands/tag.go | 3 +- internal/commands/tb.go | 8 +- internal/commands/tests.go | 3 +- 76 files changed, 332 insertions(+), 190 deletions(-) rename {_example => examples/internal}/basic/Makefile (100%) rename {_example => examples/internal}/basic/config.yaml (100%) rename {_example => examples/internal}/basic/main.go (100%) rename {_example => examples/internal}/database/Makefile (100%) rename {_example => examples/internal}/database/config.yaml (100%) rename {_example => examples/internal}/database/main.go (100%) rename {_example => examples/internal}/database/migrations/0001_data.sql (100%) rename {_example => examples/internal}/demo-console/Makefile (100%) rename {_example => examples/internal}/demo-console/main.go (100%) rename {_example => examples/internal}/dns-server/Makefile (100%) rename {_example => examples/internal}/dns-server/config.yaml (100%) rename {_example => examples/internal}/dns-server/main.go (100%) rename {_example => examples/internal}/geoip/Makefile (100%) rename {_example => examples/internal}/geoip/config.yaml (100%) rename {_example => examples/internal}/geoip/main.go (100%) rename {_example => examples/internal}/oauth/Makefile (100%) rename {_example => examples/internal}/oauth/config.yaml (100%) rename {_example => examples/internal}/oauth/main.go (100%) rename {_example => examples/internal}/orm-gen/001000_users_table.sql (100%) rename {_example => examples/internal}/orm-gen/001001_meta_table.sql (100%) rename {_example => examples/internal}/orm-gen/empty.go (100%) rename {_example => examples/internal}/orm-gen/model.go (100%) rename {_example => examples/internal}/orm-gen/repo_init_codegen.go (99%) rename {_example => examples/internal}/orm-gen/repo_meta_codegen.go (99%) rename {_example => examples/internal}/orm-gen/repo_user_codegen.go (100%) rename {_example => examples/internal}/rpc-app/Makefile (100%) rename {_example => examples/internal}/rpc-app/config.yaml (100%) rename {_example => examples/internal}/rpc-app/main.go (100%) rename {_example => examples/internal}/rpc-app/rpc-go-plugin/.build.yaml (100%) rename {_example => examples/internal}/rpc-app/rpc-go-plugin/main.go (100%) rename {_example => examples/internal}/rpc-app/rpc-unix-plugin/.build.yaml (100%) rename {_example => examples/internal}/rpc-app/rpc-unix-plugin/config.yaml (100%) rename {_example => examples/internal}/rpc-app/rpc-unix-plugin/main.go (93%) rename {_example => examples/internal}/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go (94%) rename {_example => examples/internal}/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go (100%) create mode 100644 examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model_easyjson.go rename {_example => examples/internal}/rpc-app/rpc-unix-plugin/types/interfaces.go (100%) rename {_example => examples/internal}/rpc-app/rpc-unix-plugin/types/tb.go (82%) rename {_example => examples/internal}/wasm/.build.yaml (100%) rename {_example => examples/internal}/wasm/main.go (100%) rename {_example => examples/internal}/web-server-gen/Makefile (100%) rename {_example => examples/internal}/web-server-gen/client/jsonrpc_client_api_handler.go (100%) rename {_example => examples/internal}/web-server-gen/client/jsonrpc_client_model.go (94%) rename {_example => examples/internal}/web-server-gen/client/jsonrpc_client_model_easyjson.go (67%) rename {_example => examples/internal}/web-server-gen/client/jsonrpc_client_post_handler.go (100%) rename {_example => examples/internal}/web-server-gen/client/jsonrpc_client_user_handler.go (100%) rename {_example => examples/internal}/web-server-gen/config.yaml (100%) rename {_example => examples/internal}/web-server-gen/main.go (94%) rename {_example => examples/internal}/web-server-gen/test.http (100%) rename {_example => examples/internal}/web-server-gen/transport/jsonrpc_server_api_handler.go (97%) rename {_example => examples/internal}/web-server-gen/transport/jsonrpc_server_model.go (93%) rename {_example => examples/internal}/web-server-gen/transport/jsonrpc_server_model_easyjson.go (67%) rename {_example => examples/internal}/web-server-gen/transport/jsonrpc_server_post_handler.go (96%) rename {_example => examples/internal}/web-server-gen/transport/jsonrpc_server_user_handler.go (94%) rename {_example => examples/internal}/web-server-gen/types/interfaces1.go (100%) rename {_example => examples/internal}/web-server-gen/types/interfaces2.go (100%) rename {_example => examples/internal}/web-server-gen/types/tb.go (100%) rename {_example => examples/internal}/ws-client/Makefile (100%) rename {_example => examples/internal}/ws-client/config.yaml (100%) rename {_example => examples/internal}/ws-client/main.go (94%) rename {_example => examples/internal}/ws-server/Makefile (100%) rename {_example => examples/internal}/ws-server/config.yaml (100%) rename {_example => examples/internal}/ws-server/index.html (100%) rename {_example => examples/internal}/ws-server/main.go (99%) rename internal/{gen/ormb/command.go => commands/orm.go} (88%) diff --git a/Makefile b/Makefile index a707ee18..e1e2fd87 100755 --- a/Makefile +++ b/Makefile @@ -11,7 +11,6 @@ setup: .PHONY: lint lint: goppy lint - cd _example && goppy lint .PHONY: license license: @@ -34,8 +33,3 @@ 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 ./... \ No newline at end of file diff --git a/cmd/goppy/main.go b/cmd/goppy/main.go index e27b49ce..d37bbfdc 100644 --- a/cmd/goppy/main.go +++ b/cmd/goppy/main.go @@ -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(), @@ -28,8 +28,7 @@ func main() { commands.CmdGoSite(), commands.CmdTB(), commands.CmdFS(), - ormb.Command(), + commands.CmdORM(), ) - app.Exec() } diff --git a/console/io.go b/console/io.go index 9b107f0d..d08531f9 100644 --- a/console/io.go +++ b/console/io.go @@ -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) diff --git a/_example/basic/Makefile b/examples/internal/basic/Makefile similarity index 100% rename from _example/basic/Makefile rename to examples/internal/basic/Makefile diff --git a/_example/basic/config.yaml b/examples/internal/basic/config.yaml similarity index 100% rename from _example/basic/config.yaml rename to examples/internal/basic/config.yaml diff --git a/_example/basic/main.go b/examples/internal/basic/main.go similarity index 100% rename from _example/basic/main.go rename to examples/internal/basic/main.go diff --git a/_example/database/Makefile b/examples/internal/database/Makefile similarity index 100% rename from _example/database/Makefile rename to examples/internal/database/Makefile diff --git a/_example/database/config.yaml b/examples/internal/database/config.yaml similarity index 100% rename from _example/database/config.yaml rename to examples/internal/database/config.yaml diff --git a/_example/database/main.go b/examples/internal/database/main.go similarity index 100% rename from _example/database/main.go rename to examples/internal/database/main.go diff --git a/_example/database/migrations/0001_data.sql b/examples/internal/database/migrations/0001_data.sql similarity index 100% rename from _example/database/migrations/0001_data.sql rename to examples/internal/database/migrations/0001_data.sql diff --git a/_example/demo-console/Makefile b/examples/internal/demo-console/Makefile similarity index 100% rename from _example/demo-console/Makefile rename to examples/internal/demo-console/Makefile diff --git a/_example/demo-console/main.go b/examples/internal/demo-console/main.go similarity index 100% rename from _example/demo-console/main.go rename to examples/internal/demo-console/main.go diff --git a/_example/dns-server/Makefile b/examples/internal/dns-server/Makefile similarity index 100% rename from _example/dns-server/Makefile rename to examples/internal/dns-server/Makefile diff --git a/_example/dns-server/config.yaml b/examples/internal/dns-server/config.yaml similarity index 100% rename from _example/dns-server/config.yaml rename to examples/internal/dns-server/config.yaml diff --git a/_example/dns-server/main.go b/examples/internal/dns-server/main.go similarity index 100% rename from _example/dns-server/main.go rename to examples/internal/dns-server/main.go diff --git a/_example/geoip/Makefile b/examples/internal/geoip/Makefile similarity index 100% rename from _example/geoip/Makefile rename to examples/internal/geoip/Makefile diff --git a/_example/geoip/config.yaml b/examples/internal/geoip/config.yaml similarity index 100% rename from _example/geoip/config.yaml rename to examples/internal/geoip/config.yaml diff --git a/_example/geoip/main.go b/examples/internal/geoip/main.go similarity index 100% rename from _example/geoip/main.go rename to examples/internal/geoip/main.go diff --git a/_example/oauth/Makefile b/examples/internal/oauth/Makefile similarity index 100% rename from _example/oauth/Makefile rename to examples/internal/oauth/Makefile diff --git a/_example/oauth/config.yaml b/examples/internal/oauth/config.yaml similarity index 100% rename from _example/oauth/config.yaml rename to examples/internal/oauth/config.yaml diff --git a/_example/oauth/main.go b/examples/internal/oauth/main.go similarity index 100% rename from _example/oauth/main.go rename to examples/internal/oauth/main.go diff --git a/_example/orm-gen/001000_users_table.sql b/examples/internal/orm-gen/001000_users_table.sql similarity index 100% rename from _example/orm-gen/001000_users_table.sql rename to examples/internal/orm-gen/001000_users_table.sql diff --git a/_example/orm-gen/001001_meta_table.sql b/examples/internal/orm-gen/001001_meta_table.sql similarity index 100% rename from _example/orm-gen/001001_meta_table.sql rename to examples/internal/orm-gen/001001_meta_table.sql diff --git a/_example/orm-gen/empty.go b/examples/internal/orm-gen/empty.go similarity index 100% rename from _example/orm-gen/empty.go rename to examples/internal/orm-gen/empty.go diff --git a/_example/orm-gen/model.go b/examples/internal/orm-gen/model.go similarity index 100% rename from _example/orm-gen/model.go rename to examples/internal/orm-gen/model.go diff --git a/_example/orm-gen/repo_init_codegen.go b/examples/internal/orm-gen/repo_init_codegen.go similarity index 99% rename from _example/orm-gen/repo_init_codegen.go rename to examples/internal/orm-gen/repo_init_codegen.go index a96d0bf2..12b1aa11 100755 --- a/_example/orm-gen/repo_init_codegen.go +++ b/examples/internal/orm-gen/repo_init_codegen.go @@ -10,8 +10,9 @@ import ( "fmt" "strings" - "go.osspkg.com/goppy/v3/orm" "go.osspkg.com/ioutils/pool" + + "go.osspkg.com/goppy/v3/orm" ) type Repo struct { diff --git a/_example/orm-gen/repo_meta_codegen.go b/examples/internal/orm-gen/repo_meta_codegen.go similarity index 99% rename from _example/orm-gen/repo_meta_codegen.go rename to examples/internal/orm-gen/repo_meta_codegen.go index 902c7488..799d3128 100755 --- a/_example/orm-gen/repo_meta_codegen.go +++ b/examples/internal/orm-gen/repo_meta_codegen.go @@ -11,6 +11,7 @@ import ( time "time" uuid "github.com/google/uuid" + "go.osspkg.com/goppy/v3/orm" ) diff --git a/_example/orm-gen/repo_user_codegen.go b/examples/internal/orm-gen/repo_user_codegen.go similarity index 100% rename from _example/orm-gen/repo_user_codegen.go rename to examples/internal/orm-gen/repo_user_codegen.go diff --git a/_example/rpc-app/Makefile b/examples/internal/rpc-app/Makefile similarity index 100% rename from _example/rpc-app/Makefile rename to examples/internal/rpc-app/Makefile diff --git a/_example/rpc-app/config.yaml b/examples/internal/rpc-app/config.yaml similarity index 100% rename from _example/rpc-app/config.yaml rename to examples/internal/rpc-app/config.yaml diff --git a/_example/rpc-app/main.go b/examples/internal/rpc-app/main.go similarity index 100% rename from _example/rpc-app/main.go rename to examples/internal/rpc-app/main.go diff --git a/_example/rpc-app/rpc-go-plugin/.build.yaml b/examples/internal/rpc-app/rpc-go-plugin/.build.yaml similarity index 100% rename from _example/rpc-app/rpc-go-plugin/.build.yaml rename to examples/internal/rpc-app/rpc-go-plugin/.build.yaml diff --git a/_example/rpc-app/rpc-go-plugin/main.go b/examples/internal/rpc-app/rpc-go-plugin/main.go similarity index 100% rename from _example/rpc-app/rpc-go-plugin/main.go rename to examples/internal/rpc-app/rpc-go-plugin/main.go diff --git a/_example/rpc-app/rpc-unix-plugin/.build.yaml b/examples/internal/rpc-app/rpc-unix-plugin/.build.yaml similarity index 100% rename from _example/rpc-app/rpc-unix-plugin/.build.yaml rename to examples/internal/rpc-app/rpc-unix-plugin/.build.yaml diff --git a/_example/rpc-app/rpc-unix-plugin/config.yaml b/examples/internal/rpc-app/rpc-unix-plugin/config.yaml similarity index 100% rename from _example/rpc-app/rpc-unix-plugin/config.yaml rename to examples/internal/rpc-app/rpc-unix-plugin/config.yaml diff --git a/_example/rpc-app/rpc-unix-plugin/main.go b/examples/internal/rpc-app/rpc-unix-plugin/main.go similarity index 93% rename from _example/rpc-app/rpc-unix-plugin/main.go rename to examples/internal/rpc-app/rpc-unix-plugin/main.go index 2aa417cc..737b921d 100644 --- a/_example/rpc-app/rpc-unix-plugin/main.go +++ b/examples/internal/rpc-app/rpc-unix-plugin/main.go @@ -13,8 +13,9 @@ import ( "go.osspkg.com/logx" + "go.osspkg.com/goppy/v3/examples/internal/rpc-app/rpc-unix-plugin/transport" + "go.osspkg.com/goppy/v3" - "go.osspkg.com/goppy/v3/_example/rpc-app/rpc-unix-plugin/transport" "go.osspkg.com/goppy/v3/web" "go.osspkg.com/goppy/v3/web/jsonrpc" ) diff --git a/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go b/examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go similarity index 94% rename from _example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go rename to examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go index 5e927e2d..198183cd 100644 --- a/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go +++ b/examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_api_handler.go @@ -8,15 +8,15 @@ package transport import ( context "context" - - web "go.osspkg.com/goppy/v3/web" - jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" - fmt "fmt" stdjson "encoding/json" - types "go.osspkg.com/goppy/v3/_example/rpc-app/rpc-unix-plugin/types" + jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" + + web "go.osspkg.com/goppy/v3/web" + + types "go.osspkg.com/goppy/v3/examples/internal/rpc-app/rpc-unix-plugin/types" ) type JSONRPCApiTransport struct { diff --git a/_example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go b/examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go similarity index 100% rename from _example/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go rename to examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model.go diff --git a/examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model_easyjson.go b/examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model_easyjson.go new file mode 100644 index 00000000..474509aa --- /dev/null +++ b/examples/internal/rpc-app/rpc-unix-plugin/transport/jsonrpc_server_model_easyjson.go @@ -0,0 +1,139 @@ +// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. + +package transport + +import ( + json "encoding/json" + + easyjson "github.com/mailru/easyjson" + jlexer "github.com/mailru/easyjson/jlexer" + jwriter "github.com/mailru/easyjson/jwriter" +) + +// suppress unused package warning +var ( + _ *json.RawMessage + _ *jlexer.Lexer + _ *jwriter.Writer + _ easyjson.Marshaler +) + +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport(in *jlexer.Lexer, out *jsonrpcApiPingModelResponse) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + switch key { + case "pong": + if in.IsNull() { + in.Skip() + } else { + out.Pong = bool(in.Bool()) + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport(out *jwriter.Writer, in jsonrpcApiPingModelResponse) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"pong\":" + out.RawString(prefix[1:]) + out.Bool(bool(in.Pong)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v jsonrpcApiPingModelResponse) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v jsonrpcApiPingModelResponse) MarshalEasyJSON(w *jwriter.Writer) { + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *jsonrpcApiPingModelResponse) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *jsonrpcApiPingModelResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport(l, v) +} +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport1(in *jlexer.Lexer, out *jsonrpcApiPingModelRequest) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + switch key { + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport1(out *jwriter.Writer, in jsonrpcApiPingModelRequest) { + out.RawByte('{') + first := true + _ = first + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v jsonrpcApiPingModelRequest) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport1(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v jsonrpcApiPingModelRequest) MarshalEasyJSON(w *jwriter.Writer) { + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport1(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *jsonrpcApiPingModelRequest) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport1(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *jsonrpcApiPingModelRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalRpcAppRpcUnixPluginTransport1(l, v) +} diff --git a/_example/rpc-app/rpc-unix-plugin/types/interfaces.go b/examples/internal/rpc-app/rpc-unix-plugin/types/interfaces.go similarity index 100% rename from _example/rpc-app/rpc-unix-plugin/types/interfaces.go rename to examples/internal/rpc-app/rpc-unix-plugin/types/interfaces.go diff --git a/_example/rpc-app/rpc-unix-plugin/types/tb.go b/examples/internal/rpc-app/rpc-unix-plugin/types/tb.go similarity index 82% rename from _example/rpc-app/rpc-unix-plugin/types/tb.go rename to examples/internal/rpc-app/rpc-unix-plugin/types/tb.go index 6bcddcf5..91140578 100644 --- a/_example/rpc-app/rpc-unix-plugin/types/tb.go +++ b/examples/internal/rpc-app/rpc-unix-plugin/types/tb.go @@ -6,3 +6,4 @@ package types //go:generate goppy tb --mod=json-rpc-server --out=./../transport +//go:generate easyjson ./../transport/jsonrpc_server_model.go diff --git a/_example/wasm/.build.yaml b/examples/internal/wasm/.build.yaml similarity index 100% rename from _example/wasm/.build.yaml rename to examples/internal/wasm/.build.yaml diff --git a/_example/wasm/main.go b/examples/internal/wasm/main.go similarity index 100% rename from _example/wasm/main.go rename to examples/internal/wasm/main.go diff --git a/_example/web-server-gen/Makefile b/examples/internal/web-server-gen/Makefile similarity index 100% rename from _example/web-server-gen/Makefile rename to examples/internal/web-server-gen/Makefile diff --git a/_example/web-server-gen/client/jsonrpc_client_api_handler.go b/examples/internal/web-server-gen/client/jsonrpc_client_api_handler.go similarity index 100% rename from _example/web-server-gen/client/jsonrpc_client_api_handler.go rename to examples/internal/web-server-gen/client/jsonrpc_client_api_handler.go diff --git a/_example/web-server-gen/client/jsonrpc_client_model.go b/examples/internal/web-server-gen/client/jsonrpc_client_model.go similarity index 94% rename from _example/web-server-gen/client/jsonrpc_client_model.go rename to examples/internal/web-server-gen/client/jsonrpc_client_model.go index 7e6256b3..4c905587 100644 --- a/_example/web-server-gen/client/jsonrpc_client_model.go +++ b/examples/internal/web-server-gen/client/jsonrpc_client_model.go @@ -7,7 +7,7 @@ package client //go:generate easyjson -import types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" +import types "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/types" //easyjson:json type ApiRootV1Request struct { diff --git a/_example/web-server-gen/client/jsonrpc_client_model_easyjson.go b/examples/internal/web-server-gen/client/jsonrpc_client_model_easyjson.go similarity index 67% rename from _example/web-server-gen/client/jsonrpc_client_model_easyjson.go rename to examples/internal/web-server-gen/client/jsonrpc_client_model_easyjson.go index e6a23c1f..a7bbcfe9 100644 --- a/_example/web-server-gen/client/jsonrpc_client_model_easyjson.go +++ b/examples/internal/web-server-gen/client/jsonrpc_client_model_easyjson.go @@ -8,7 +8,8 @@ import ( easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" jwriter "github.com/mailru/easyjson/jwriter" - types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" + + types "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/types" ) // suppress unused package warning @@ -19,7 +20,7 @@ var ( _ easyjson.Marshaler ) -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient(in *jlexer.Lexer, out *UserNameV1Response) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient(in *jlexer.Lexer, out *UserNameV1Response) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -49,7 +50,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient(in *jlexe in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient(out *jwriter.Writer, in UserNameV1Response) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient(out *jwriter.Writer, in UserNameV1Response) { out.RawByte('{') first := true _ = first @@ -64,27 +65,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient(out *jwri // MarshalJSON supports json.Marshaler interface func (v UserNameV1Response) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v UserNameV1Response) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *UserNameV1Response) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *UserNameV1Response) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient1(in *jlexer.Lexer, out *UserNameV1Request) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient1(in *jlexer.Lexer, out *UserNameV1Request) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -114,7 +115,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient1(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient1(out *jwriter.Writer, in UserNameV1Request) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient1(out *jwriter.Writer, in UserNameV1Request) { out.RawByte('{') first := true _ = first @@ -129,27 +130,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient1(out *jwr // MarshalJSON supports json.Marshaler interface func (v UserNameV1Request) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient1(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient1(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v UserNameV1Request) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient1(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient1(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *UserNameV1Request) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient1(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient1(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *UserNameV1Request) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient1(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient1(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(in *jlexer.Lexer, out *PostListResponse) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient2(in *jlexer.Lexer, out *PostListResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -180,7 +181,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(in *jlex } for !in.IsDelim(']') { var v1 types.Text - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(in, &v1) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTypes(in, &v1) out.Text = append(out.Text, v1) in.WantComma() } @@ -196,7 +197,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(out *jwriter.Writer, in PostListResponse) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient2(out *jwriter.Writer, in PostListResponse) { out.RawByte('{') first := true _ = first @@ -210,7 +211,7 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(out *jwr if v2 > 0 { out.RawByte(',') } - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(out, v3) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTypes(out, v3) } out.RawByte(']') } @@ -221,27 +222,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(out *jwr // MarshalJSON supports json.Marshaler interface func (v PostListResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient2(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v PostListResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient2(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *PostListResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient2(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *PostListResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient2(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient2(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(in *jlexer.Lexer, out *types.Text) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTypes(in *jlexer.Lexer, out *types.Text) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -277,7 +278,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(in *jlexer in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(out *jwriter.Writer, in types.Text) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTypes(out *jwriter.Writer, in types.Text) { out.RawByte('{') first := true _ = first @@ -293,7 +294,7 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(out *jwrit } out.RawByte('}') } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient3(in *jlexer.Lexer, out *PostListRequest) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient3(in *jlexer.Lexer, out *PostListRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -323,7 +324,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient3(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient3(out *jwriter.Writer, in PostListRequest) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient3(out *jwriter.Writer, in PostListRequest) { out.RawByte('{') first := true _ = first @@ -338,27 +339,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient3(out *jwr // MarshalJSON supports json.Marshaler interface func (v PostListRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient3(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient3(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v PostListRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient3(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient3(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *PostListRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient3(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient3(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *PostListRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient3(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient3(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient4(in *jlexer.Lexer, out *PostByIDResponse) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient4(in *jlexer.Lexer, out *PostByIDResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -388,7 +389,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient4(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient4(out *jwriter.Writer, in PostByIDResponse) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient4(out *jwriter.Writer, in PostByIDResponse) { out.RawByte('{') first := true _ = first @@ -403,27 +404,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient4(out *jwr // MarshalJSON supports json.Marshaler interface func (v PostByIDResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient4(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient4(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v PostByIDResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient4(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient4(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *PostByIDResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient4(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient4(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *PostByIDResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient4(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient4(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient5(in *jlexer.Lexer, out *PostByIDRequest) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient5(in *jlexer.Lexer, out *PostByIDRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -453,7 +454,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient5(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient5(out *jwriter.Writer, in PostByIDRequest) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient5(out *jwriter.Writer, in PostByIDRequest) { out.RawByte('{') first := true _ = first @@ -468,27 +469,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient5(out *jwr // MarshalJSON supports json.Marshaler interface func (v PostByIDRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient5(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient5(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v PostByIDRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient5(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient5(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *PostByIDRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient5(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient5(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *PostByIDRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient5(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient5(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient6(in *jlexer.Lexer, out *ApiRootV1Response) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient6(in *jlexer.Lexer, out *ApiRootV1Response) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -518,7 +519,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient6(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient6(out *jwriter.Writer, in ApiRootV1Response) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient6(out *jwriter.Writer, in ApiRootV1Response) { out.RawByte('{') first := true _ = first @@ -533,27 +534,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient6(out *jwr // MarshalJSON supports json.Marshaler interface func (v ApiRootV1Response) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient6(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient6(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v ApiRootV1Response) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient6(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient6(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *ApiRootV1Response) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient6(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient6(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *ApiRootV1Response) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient6(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient6(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient7(in *jlexer.Lexer, out *ApiRootV1Request) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient7(in *jlexer.Lexer, out *ApiRootV1Request) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -583,7 +584,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient7(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient7(out *jwriter.Writer, in ApiRootV1Request) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient7(out *jwriter.Writer, in ApiRootV1Request) { out.RawByte('{') first := true _ = first @@ -598,27 +599,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient7(out *jwr // MarshalJSON supports json.Marshaler interface func (v ApiRootV1Request) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient7(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient7(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v ApiRootV1Request) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient7(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient7(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *ApiRootV1Request) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient7(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient7(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *ApiRootV1Request) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient7(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient7(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient8(in *jlexer.Lexer, out *ApiAuthV1Response) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient8(in *jlexer.Lexer, out *ApiAuthV1Response) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -642,7 +643,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient8(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient8(out *jwriter.Writer, in ApiAuthV1Response) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient8(out *jwriter.Writer, in ApiAuthV1Response) { out.RawByte('{') first := true _ = first @@ -652,27 +653,27 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient8(out *jwr // MarshalJSON supports json.Marshaler interface func (v ApiAuthV1Response) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient8(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient8(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v ApiAuthV1Response) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient8(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient8(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *ApiAuthV1Response) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient8(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient8(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *ApiAuthV1Response) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient8(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient8(l, v) } -func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient9(in *jlexer.Lexer, out *ApiAuthV1Request) { +func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient9(in *jlexer.Lexer, out *ApiAuthV1Request) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -702,7 +703,7 @@ func easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient9(in *jlex in.Consumed() } } -func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient9(out *jwriter.Writer, in ApiAuthV1Request) { +func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient9(out *jwriter.Writer, in ApiAuthV1Request) { out.RawByte('{') first := true _ = first @@ -717,23 +718,23 @@ func easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient9(out *jwr // MarshalJSON supports json.Marshaler interface func (v ApiAuthV1Request) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient9(&w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient9(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v ApiAuthV1Request) MarshalEasyJSON(w *jwriter.Writer) { - easyjson93e197c5EncodeGoOsspkgComGoppyV3ExampleWebServerGenClient9(w, v) + easyjson93e197c5EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient9(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *ApiAuthV1Request) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient9(&r, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient9(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *ApiAuthV1Request) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson93e197c5DecodeGoOsspkgComGoppyV3ExampleWebServerGenClient9(l, v) + easyjson93e197c5DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenClient9(l, v) } diff --git a/_example/web-server-gen/client/jsonrpc_client_post_handler.go b/examples/internal/web-server-gen/client/jsonrpc_client_post_handler.go similarity index 100% rename from _example/web-server-gen/client/jsonrpc_client_post_handler.go rename to examples/internal/web-server-gen/client/jsonrpc_client_post_handler.go diff --git a/_example/web-server-gen/client/jsonrpc_client_user_handler.go b/examples/internal/web-server-gen/client/jsonrpc_client_user_handler.go similarity index 100% rename from _example/web-server-gen/client/jsonrpc_client_user_handler.go rename to examples/internal/web-server-gen/client/jsonrpc_client_user_handler.go diff --git a/_example/web-server-gen/config.yaml b/examples/internal/web-server-gen/config.yaml similarity index 100% rename from _example/web-server-gen/config.yaml rename to examples/internal/web-server-gen/config.yaml diff --git a/_example/web-server-gen/main.go b/examples/internal/web-server-gen/main.go similarity index 94% rename from _example/web-server-gen/main.go rename to examples/internal/web-server-gen/main.go index 1b1b3496..16650ea0 100644 --- a/_example/web-server-gen/main.go +++ b/examples/internal/web-server-gen/main.go @@ -13,8 +13,8 @@ import ( "go.osspkg.com/logx" "go.osspkg.com/goppy/v3" - "go.osspkg.com/goppy/v3/_example/web-server-gen/transport" - "go.osspkg.com/goppy/v3/_example/web-server-gen/types" + "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/transport" + "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/types" "go.osspkg.com/goppy/v3/web" "go.osspkg.com/goppy/v3/web/jsonrpc" ) diff --git a/_example/web-server-gen/test.http b/examples/internal/web-server-gen/test.http similarity index 100% rename from _example/web-server-gen/test.http rename to examples/internal/web-server-gen/test.http diff --git a/_example/web-server-gen/transport/jsonrpc_server_api_handler.go b/examples/internal/web-server-gen/transport/jsonrpc_server_api_handler.go similarity index 97% rename from _example/web-server-gen/transport/jsonrpc_server_api_handler.go rename to examples/internal/web-server-gen/transport/jsonrpc_server_api_handler.go index 5767e4ea..67484e55 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_api_handler.go +++ b/examples/internal/web-server-gen/transport/jsonrpc_server_api_handler.go @@ -7,22 +7,22 @@ package transport import ( + context "context" stdjson "encoding/json" - types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" + web "go.osspkg.com/goppy/v3/web" + jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" - cast "go.osspkg.com/cast" + types "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/types" nethttp "net/http" time "time" - context "context" - fmt "fmt" - web "go.osspkg.com/goppy/v3/web" + cast "go.osspkg.com/cast" ) type JSONRPCApiTransport struct { diff --git a/_example/web-server-gen/transport/jsonrpc_server_model.go b/examples/internal/web-server-gen/transport/jsonrpc_server_model.go similarity index 93% rename from _example/web-server-gen/transport/jsonrpc_server_model.go rename to examples/internal/web-server-gen/transport/jsonrpc_server_model.go index edb23164..7e717c2f 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_model.go +++ b/examples/internal/web-server-gen/transport/jsonrpc_server_model.go @@ -7,7 +7,7 @@ package transport //go:generate easyjson -import types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" +import types "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/types" //easyjson:json type jsonrpcApiRootV1ModelRequest struct { diff --git a/_example/web-server-gen/transport/jsonrpc_server_model_easyjson.go b/examples/internal/web-server-gen/transport/jsonrpc_server_model_easyjson.go similarity index 67% rename from _example/web-server-gen/transport/jsonrpc_server_model_easyjson.go rename to examples/internal/web-server-gen/transport/jsonrpc_server_model_easyjson.go index 2a0524fc..c0045324 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_model_easyjson.go +++ b/examples/internal/web-server-gen/transport/jsonrpc_server_model_easyjson.go @@ -8,7 +8,8 @@ import ( easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" jwriter "github.com/mailru/easyjson/jwriter" - types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" + + types "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/types" ) // suppress unused package warning @@ -19,7 +20,7 @@ var ( _ easyjson.Marshaler ) -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport(in *jlexer.Lexer, out *jsonrpcUserNameV1ModelResponse) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport(in *jlexer.Lexer, out *jsonrpcUserNameV1ModelResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -49,7 +50,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport(in *jl in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport(out *jwriter.Writer, in jsonrpcUserNameV1ModelResponse) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport(out *jwriter.Writer, in jsonrpcUserNameV1ModelResponse) { out.RawByte('{') first := true _ = first @@ -64,27 +65,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport(out *j // MarshalJSON supports json.Marshaler interface func (v jsonrpcUserNameV1ModelResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcUserNameV1ModelResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcUserNameV1ModelResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcUserNameV1ModelResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport1(in *jlexer.Lexer, out *jsonrpcUserNameV1ModelRequest) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport1(in *jlexer.Lexer, out *jsonrpcUserNameV1ModelRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -114,7 +115,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport1(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport1(out *jwriter.Writer, in jsonrpcUserNameV1ModelRequest) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport1(out *jwriter.Writer, in jsonrpcUserNameV1ModelRequest) { out.RawByte('{') first := true _ = first @@ -129,27 +130,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport1(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcUserNameV1ModelRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport1(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport1(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcUserNameV1ModelRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport1(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport1(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcUserNameV1ModelRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport1(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport1(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcUserNameV1ModelRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport1(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport1(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(in *jlexer.Lexer, out *jsonrpcPostListModelResponse) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport2(in *jlexer.Lexer, out *jsonrpcPostListModelResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -180,7 +181,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(in *j } for !in.IsDelim(']') { var v1 types.Text - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(in, &v1) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTypes(in, &v1) out.Text = append(out.Text, v1) in.WantComma() } @@ -196,7 +197,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(out *jwriter.Writer, in jsonrpcPostListModelResponse) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport2(out *jwriter.Writer, in jsonrpcPostListModelResponse) { out.RawByte('{') first := true _ = first @@ -210,7 +211,7 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(out * if v2 > 0 { out.RawByte(',') } - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(out, v3) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTypes(out, v3) } out.RawByte(']') } @@ -221,27 +222,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcPostListModelResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport2(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcPostListModelResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport2(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcPostListModelResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport2(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcPostListModelResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport2(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport2(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(in *jlexer.Lexer, out *types.Text) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTypes(in *jlexer.Lexer, out *types.Text) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -277,7 +278,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(in *jlexer in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(out *jwriter.Writer, in types.Text) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTypes(out *jwriter.Writer, in types.Text) { out.RawByte('{') first := true _ = first @@ -293,7 +294,7 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTypes(out *jwrit } out.RawByte('}') } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport3(in *jlexer.Lexer, out *jsonrpcPostListModelRequest) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport3(in *jlexer.Lexer, out *jsonrpcPostListModelRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -323,7 +324,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport3(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport3(out *jwriter.Writer, in jsonrpcPostListModelRequest) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport3(out *jwriter.Writer, in jsonrpcPostListModelRequest) { out.RawByte('{') first := true _ = first @@ -338,27 +339,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport3(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcPostListModelRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport3(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport3(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcPostListModelRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport3(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport3(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcPostListModelRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport3(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport3(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcPostListModelRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport3(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport3(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport4(in *jlexer.Lexer, out *jsonrpcPostByIDModelResponse) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport4(in *jlexer.Lexer, out *jsonrpcPostByIDModelResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -388,7 +389,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport4(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport4(out *jwriter.Writer, in jsonrpcPostByIDModelResponse) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport4(out *jwriter.Writer, in jsonrpcPostByIDModelResponse) { out.RawByte('{') first := true _ = first @@ -403,27 +404,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport4(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcPostByIDModelResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport4(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport4(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcPostByIDModelResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport4(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport4(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcPostByIDModelResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport4(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport4(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcPostByIDModelResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport4(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport4(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport5(in *jlexer.Lexer, out *jsonrpcPostByIDModelRequest) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport5(in *jlexer.Lexer, out *jsonrpcPostByIDModelRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -453,7 +454,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport5(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport5(out *jwriter.Writer, in jsonrpcPostByIDModelRequest) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport5(out *jwriter.Writer, in jsonrpcPostByIDModelRequest) { out.RawByte('{') first := true _ = first @@ -468,27 +469,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport5(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcPostByIDModelRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport5(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport5(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcPostByIDModelRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport5(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport5(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcPostByIDModelRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport5(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport5(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcPostByIDModelRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport5(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport5(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport6(in *jlexer.Lexer, out *jsonrpcApiRootV1ModelResponse) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport6(in *jlexer.Lexer, out *jsonrpcApiRootV1ModelResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -518,7 +519,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport6(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport6(out *jwriter.Writer, in jsonrpcApiRootV1ModelResponse) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport6(out *jwriter.Writer, in jsonrpcApiRootV1ModelResponse) { out.RawByte('{') first := true _ = first @@ -533,27 +534,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport6(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcApiRootV1ModelResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport6(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport6(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcApiRootV1ModelResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport6(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport6(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcApiRootV1ModelResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport6(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport6(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcApiRootV1ModelResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport6(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport6(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport7(in *jlexer.Lexer, out *jsonrpcApiRootV1ModelRequest) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport7(in *jlexer.Lexer, out *jsonrpcApiRootV1ModelRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -583,7 +584,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport7(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport7(out *jwriter.Writer, in jsonrpcApiRootV1ModelRequest) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport7(out *jwriter.Writer, in jsonrpcApiRootV1ModelRequest) { out.RawByte('{') first := true _ = first @@ -598,27 +599,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport7(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcApiRootV1ModelRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport7(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport7(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcApiRootV1ModelRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport7(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport7(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcApiRootV1ModelRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport7(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport7(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcApiRootV1ModelRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport7(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport7(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport8(in *jlexer.Lexer, out *jsonrpcApiAuthV1ModelResponse) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport8(in *jlexer.Lexer, out *jsonrpcApiAuthV1ModelResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -642,7 +643,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport8(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport8(out *jwriter.Writer, in jsonrpcApiAuthV1ModelResponse) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport8(out *jwriter.Writer, in jsonrpcApiAuthV1ModelResponse) { out.RawByte('{') first := true _ = first @@ -652,27 +653,27 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport8(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcApiAuthV1ModelResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport8(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport8(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcApiAuthV1ModelResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport8(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport8(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcApiAuthV1ModelResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport8(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport8(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcApiAuthV1ModelResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport8(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport8(l, v) } -func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport9(in *jlexer.Lexer, out *jsonrpcApiAuthV1ModelRequest) { +func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport9(in *jlexer.Lexer, out *jsonrpcApiAuthV1ModelRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -702,7 +703,7 @@ func easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport9(in *j in.Consumed() } } -func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport9(out *jwriter.Writer, in jsonrpcApiAuthV1ModelRequest) { +func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport9(out *jwriter.Writer, in jsonrpcApiAuthV1ModelRequest) { out.RawByte('{') first := true _ = first @@ -717,23 +718,23 @@ func easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport9(out * // MarshalJSON supports json.Marshaler interface func (v jsonrpcApiAuthV1ModelRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport9(&w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport9(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v jsonrpcApiAuthV1ModelRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3ef10231EncodeGoOsspkgComGoppyV3ExampleWebServerGenTransport9(w, v) + easyjson3ef10231EncodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport9(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *jsonrpcApiAuthV1ModelRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport9(&r, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport9(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *jsonrpcApiAuthV1ModelRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3ef10231DecodeGoOsspkgComGoppyV3ExampleWebServerGenTransport9(l, v) + easyjson3ef10231DecodeGoOsspkgComGoppyV3ExamplesInternalWebServerGenTransport9(l, v) } diff --git a/_example/web-server-gen/transport/jsonrpc_server_post_handler.go b/examples/internal/web-server-gen/transport/jsonrpc_server_post_handler.go similarity index 96% rename from _example/web-server-gen/transport/jsonrpc_server_post_handler.go rename to examples/internal/web-server-gen/transport/jsonrpc_server_post_handler.go index 8abeee72..cd215ce1 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_post_handler.go +++ b/examples/internal/web-server-gen/transport/jsonrpc_server_post_handler.go @@ -8,15 +8,15 @@ package transport import ( context "context" - fmt "fmt" - stdjson "encoding/json" - jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" - web "go.osspkg.com/goppy/v3/web" - types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" + types "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/types" + + fmt "fmt" + + jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" ) type JSONRPCPostTransport struct { diff --git a/_example/web-server-gen/transport/jsonrpc_server_user_handler.go b/examples/internal/web-server-gen/transport/jsonrpc_server_user_handler.go similarity index 94% rename from _example/web-server-gen/transport/jsonrpc_server_user_handler.go rename to examples/internal/web-server-gen/transport/jsonrpc_server_user_handler.go index a1ee423a..cf6e5fab 100644 --- a/_example/web-server-gen/transport/jsonrpc_server_user_handler.go +++ b/examples/internal/web-server-gen/transport/jsonrpc_server_user_handler.go @@ -8,15 +8,16 @@ package transport import ( stdjson "encoding/json" - fmt "fmt" - jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" + web "go.osspkg.com/goppy/v3/web" + + types "go.osspkg.com/goppy/v3/examples/internal/web-server-gen/types" context "context" - web "go.osspkg.com/goppy/v3/web" + fmt "fmt" - types "go.osspkg.com/goppy/v3/_example/web-server-gen/types" + jsonrpc "go.osspkg.com/goppy/v3/web/jsonrpc" ) type JSONRPCUserTransport struct { diff --git a/_example/web-server-gen/types/interfaces1.go b/examples/internal/web-server-gen/types/interfaces1.go similarity index 100% rename from _example/web-server-gen/types/interfaces1.go rename to examples/internal/web-server-gen/types/interfaces1.go diff --git a/_example/web-server-gen/types/interfaces2.go b/examples/internal/web-server-gen/types/interfaces2.go similarity index 100% rename from _example/web-server-gen/types/interfaces2.go rename to examples/internal/web-server-gen/types/interfaces2.go diff --git a/_example/web-server-gen/types/tb.go b/examples/internal/web-server-gen/types/tb.go similarity index 100% rename from _example/web-server-gen/types/tb.go rename to examples/internal/web-server-gen/types/tb.go diff --git a/_example/ws-client/Makefile b/examples/internal/ws-client/Makefile similarity index 100% rename from _example/ws-client/Makefile rename to examples/internal/ws-client/Makefile diff --git a/_example/ws-client/config.yaml b/examples/internal/ws-client/config.yaml similarity index 100% rename from _example/ws-client/config.yaml rename to examples/internal/ws-client/config.yaml diff --git a/_example/ws-client/main.go b/examples/internal/ws-client/main.go similarity index 94% rename from _example/ws-client/main.go rename to examples/internal/ws-client/main.go index 1c4ca072..5ba887a8 100644 --- a/_example/ws-client/main.go +++ b/examples/internal/ws-client/main.go @@ -49,10 +49,11 @@ func (v *Controller) Ticker(call func(event.Id, any) error) { t := time.NewTicker(time.Second * 3) defer t.Stop() + //nolint:staticcheck for { select { case <-t.C: - call(1, []int{0}) + call(1, []int{0}) //nolint:staticcheck,errcheck } } } diff --git a/_example/ws-server/Makefile b/examples/internal/ws-server/Makefile similarity index 100% rename from _example/ws-server/Makefile rename to examples/internal/ws-server/Makefile diff --git a/_example/ws-server/config.yaml b/examples/internal/ws-server/config.yaml similarity index 100% rename from _example/ws-server/config.yaml rename to examples/internal/ws-server/config.yaml diff --git a/_example/ws-server/index.html b/examples/internal/ws-server/index.html similarity index 100% rename from _example/ws-server/index.html rename to examples/internal/ws-server/index.html diff --git a/_example/ws-server/main.go b/examples/internal/ws-server/main.go similarity index 99% rename from _example/ws-server/main.go rename to examples/internal/ws-server/main.go index 014ad6c3..79106405 100644 --- a/_example/ws-server/main.go +++ b/examples/internal/ws-server/main.go @@ -111,6 +111,7 @@ func (v *Controller) Timer() { t := time.NewTicker(time.Second * 3) defer t.Stop() + //nolint:staticcheck for { select { case tt := <-t.C: diff --git a/internal/commands/build.go b/internal/commands/build.go index 858dbcdb..7914d01e 100644 --- a/internal/commands/build.go +++ b/internal/commands/build.go @@ -37,7 +37,7 @@ func CmdBuild() console.CommandGetter { flagsSetter.Bool("cgo", "set CGO_ENABLED=1 for build") }) setter.ExecFunc(func(_ []string, _arch, _mode, _main string, _cgo bool) { - console.Infof("--- BUILD ---") + console.Infof("goppy build") pack := make([]string, 0, 10) buildDir := global.GetBuildDir() diff --git a/internal/commands/gosite.go b/internal/commands/gosite.go index ada06dbd..53480754 100644 --- a/internal/commands/gosite.go +++ b/internal/commands/gosite.go @@ -16,7 +16,6 @@ import ( "go.osspkg.com/ioutils/fs" "go.osspkg.com/goppy/v3/console" - "go.osspkg.com/goppy/v3/internal/global" ) @@ -36,7 +35,7 @@ func CmdGoSite() console.CommandGetter { return console.NewCommand(func(setter console.CommandSetter) { setter.Setup("gosite", "Generate go pkg html") setter.ExecFunc(func(_ []string) { - console.Infof("--- READ CONFIG ---") + console.Infof("goppy gosite") confpath := fs.CurrentDir() + "/.gosite.yaml" if !fs.FileExist(confpath) { diff --git a/internal/commands/license.go b/internal/commands/license.go index f4e54f2a..0f525afc 100644 --- a/internal/commands/license.go +++ b/internal/commands/license.go @@ -30,7 +30,7 @@ func CmdLicense() console.CommandGetter { return console.NewCommand(func(setter console.CommandSetter) { setter.Setup("license", "Update license information") setter.ExecFunc(func(_ []string) { - console.Infof("--- LICENSE ---") + console.Infof("goppy license") model := &License{} if !fs.FileExist(licFilename) { diff --git a/internal/commands/lint.go b/internal/commands/lint.go index 2f345a08..fe9f348b 100644 --- a/internal/commands/lint.go +++ b/internal/commands/lint.go @@ -19,7 +19,7 @@ func CmdLint() console.CommandGetter { return console.NewCommand(func(setter console.CommandSetter) { setter.Setup("lint", "Linting code") setter.ExecFunc(func(_ []string) { - console.Infof("--- LINT ---") + console.Infof("goppy lint") updateGoMod() diff --git a/internal/gen/ormb/command.go b/internal/commands/orm.go similarity index 88% rename from internal/gen/ormb/command.go rename to internal/commands/orm.go index 9f53afd7..924e0b74 100644 --- a/internal/gen/ormb/command.go +++ b/internal/commands/orm.go @@ -3,7 +3,7 @@ * Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file. */ -package ormb +package commands import ( "go/ast" @@ -13,8 +13,9 @@ import ( "go.osspkg.com/ioutils/fs" "go.osspkg.com/syncing" - "go.osspkg.com/goppy/v3/console" + "go.osspkg.com/goppy/v3/internal/gen/ormb" + "go.osspkg.com/goppy/v3/console" "go.osspkg.com/goppy/v3/internal/gen/ormb/common" "go.osspkg.com/goppy/v3/internal/gen/ormb/dialects" "go.osspkg.com/goppy/v3/internal/gen/ormb/visitor" @@ -22,7 +23,7 @@ import ( "go.osspkg.com/goppy/v3/orm/dialect" ) -func Command() console.CommandGetter { +func CmdORM() console.CommandGetter { return console.NewCommand(func(setter console.CommandSetter) { setter.Setup("gen-orm", "generate code for orm") setter.Flag(func(flagsSetter console.FlagsSetter) { @@ -34,9 +35,7 @@ func Command() console.CommandGetter { flagsSetter.IntVar("index", 0, "index for sql file as prefix") }) setter.ExecFunc(func(_ []string, _dialect, _dbRead, _dbWrite, _outDir, _modelName string, _index int64) { - console.Infof("--- GENERATE ---") - - console.ShowDebug(false) + console.Infof("goppy gen-orm") gen, ok := dialects.Get(dialect.Name(_dialect)) if !ok { @@ -76,8 +75,8 @@ func Command() console.CommandGetter { ModelName: _modelName, } - console.FatalIfErr(GenerateSQL(cc, vv, gen), "generate orm sql") - console.FatalIfErr(GenerateCode(cc, vv, gen), "generate orm code") + console.FatalIfErr(ormb.GenerateSQL(cc, vv, gen), "generate orm sql") + console.FatalIfErr(ormb.GenerateCode(cc, vv, gen), "generate orm code") } global.ExecPack(true, "gofmt -w -s .", "goimports -l -w .") diff --git a/internal/commands/setup.go b/internal/commands/setup.go index babf5864..118118ea 100644 --- a/internal/commands/setup.go +++ b/internal/commands/setup.go @@ -15,7 +15,6 @@ import ( "go.osspkg.com/ioutils/fs" "go.osspkg.com/goppy/v3/console" - "go.osspkg.com/goppy/v3/internal/global" ) @@ -26,7 +25,7 @@ func CmdSetupLib() console.CommandGetter { flagsSetter.Bool("force", "force update") }) setter.ExecFunc(func(_ []string, force bool) { - console.Infof("--- SETUP LIB ---") + console.Infof("goppy setup-lib") updateGitIgnore() installTools() @@ -43,7 +42,7 @@ func CmdSetupApp() console.CommandGetter { flagsSetter.Bool("force", "force update") }) setter.ExecFunc(func(_ []string, force bool) { - console.Infof("--- SETUP APP ---") + console.Infof("goppy setup-app") updateGitIgnore() installTools() diff --git a/internal/commands/tag.go b/internal/commands/tag.go index 974005ad..e7c73089 100644 --- a/internal/commands/tag.go +++ b/internal/commands/tag.go @@ -17,7 +17,6 @@ import ( "golang.org/x/mod/modfile" "go.osspkg.com/goppy/v3/console" - "go.osspkg.com/goppy/v3/internal/global" ) @@ -28,7 +27,7 @@ func Cmd() console.CommandGetter { fs.Bool("minor", "update minor version (default - patch)") }) setter.ExecFunc(func(_ []string, minor bool) { - console.Infof("--- READ CONFIG ---") + console.Infof("goppy tag") var ( allMods map[string]*global.Module diff --git a/internal/commands/tb.go b/internal/commands/tb.go index f14ba766..ab264524 100644 --- a/internal/commands/tb.go +++ b/internal/commands/tb.go @@ -28,8 +28,7 @@ func CmdTB() console.CommandGetter { flagsSetter.StringVar("mod", "json-rpc", "generation modules (optional)") }) setter.ExecFunc(func(out, _iface, _mod string) { - console.ShowDebug(true) - console.Infof("--- GENERATE ---") + console.Infof("goppy tb") curDir := fs.CurrentDir() @@ -82,7 +81,10 @@ func CmdTB() console.CommandGetter { console.FatalIfErr(e, "parse go file: %s", filePath) } - vv.DumpStdout() + if console.CanShowDebug() { + vv.DumpStdout() + } + build.Files = append(build.Files, vv.ToFile()) } diff --git a/internal/commands/tests.go b/internal/commands/tests.go index 6b8dde1a..0f771244 100644 --- a/internal/commands/tests.go +++ b/internal/commands/tests.go @@ -9,7 +9,6 @@ import ( "os" "go.osspkg.com/goppy/v3/console" - "go.osspkg.com/goppy/v3/internal/global" ) @@ -17,7 +16,7 @@ func CmdTest() console.CommandGetter { return console.NewCommand(func(setter console.CommandSetter) { setter.Setup("test", "Testing code") setter.ExecFunc(func(_ []string) { - console.Infof("--- TESTS ---") + console.Infof("goppy test") pack := []string{ "go clean -testcache", From 2ef93862c5d2a19dbc6be19851edfc534e17c82f Mon Sep 17 00:00:00 2001 From: Mikhail Knyazhev Date: Sun, 26 Apr 2026 01:19:06 +0300 Subject: [PATCH 3/3] add rpc plugin support --- internal/commands/build.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/commands/build.go b/internal/commands/build.go index 7914d01e..1cd0f78b 100644 --- a/internal/commands/build.go +++ b/internal/commands/build.go @@ -41,6 +41,7 @@ func CmdBuild() console.CommandGetter { pack := make([]string, 0, 10) buildDir := global.GetBuildDir() + console.FatalIfErr(os.MkdirAll(buildDir, 0744), "create build dir") var mainFiles []string var err error @@ -121,12 +122,10 @@ func CmdBuild() console.CommandGetter { "CGO_ENABLED=0", `go build -ldflags='-s -w' -a -o `+buildDir+"/"+appName+".wasm "+main) pack = append(pack, "cp -rf \"$(go env GOROOT)/lib/wasm/wasm_exec.js\" "+buildDir+"/wasm_exec.js") - console.FatalIfErr( - os.WriteFile( - buildDir+"/"+appName+".html", - []byte(fmt.Sprintf(htmlWasmTmpl, appName)), - 0644), - "write html") + console.FatalIfErr(os.WriteFile( + buildDir+"/"+appName+".html", + []byte(fmt.Sprintf(htmlWasmTmpl, appName)), + 0644), "write html") default: console.Warnf("possible only mode: app,plugin,wasm")