Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20250126/fix error rpcut #215

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 1.3.X

### 1.3.2

- BUG: fix not load env by @poteto0 in #215

### 1.3.1

- DEBUG: add some debug mode log by @poteto0 in #213
Expand Down
9 changes: 1 addition & 8 deletions constant/constant.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package constant

const VERSION = "v1.3.1"

// env
const (
WITH_REQUEST_ID string = "WITH_REQUEST_ID"
DEBUG_MODE string = "DEBUG_MODE"
LISTENER_NETWORK string = "LISTENER_NETWORK"
)
const VERSION = "v1.3.2"

const (
MAX_DOMAIN_LENGTH int = 255
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23

require (
bou.ke/monkey v1.0.2
github.com/caarlos0/env/v11 v11.3.1
github.com/fatih/color v1.18.0
github.com/goccy/go-json v0.10.4
github.com/goccy/go-yaml v1.15.15
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI=
bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA=
github.com/caarlos0/env/v11 v11.3.1 h1:cArPWC15hWmEt+gWk7YBi7lEXTXCvpaSdCiZE2X5mCA=
github.com/caarlos0/env/v11 v11.3.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
Expand Down
5 changes: 5 additions & 0 deletions poteto.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

stdContext "context"

"github.com/caarlos0/env/v11"
"github.com/fatih/color"
"github.com/poteto-go/poteto/constant"
"github.com/poteto-go/poteto/utils"
Expand Down Expand Up @@ -57,6 +58,9 @@ type poteto struct {
}

func New() Poteto {
var DefaultPotetoOption PotetoOption
env.Parse(&DefaultPotetoOption)

return &poteto{
router: NewRouter(),
errorHandler: &httpErrorHandler{},
Expand Down Expand Up @@ -258,6 +262,7 @@ func (p *poteto) setupServer() error {

// set listener
if p.Listener == nil {
utils.PotetoPrint(p.option.ListenerNetwork + "\n")
ln, err := net.Listen(p.option.ListenerNetwork, p.Server.Addr)
if err != nil {
if p.option.DebugMode {
Expand Down
2 changes: 0 additions & 2 deletions poteto_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ type PotetoOption struct {
DebugMode bool `yaml:"debug_mode" env:"DEBUG_MODE" envDefault:"false"`
ListenerNetwork string `yaml:"listener_network" env:"LISTENER_NETWORK" envDefault:"tcp"`
}

var DefaultPotetoOption = PotetoOption{}
15 changes: 9 additions & 6 deletions poteto_rpc_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package poteto

import (
stdContext "context"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

"github.com/goccy/go-json"
"github.com/poteto-go/poteto/constant"
"github.com/ybbus/jsonrpc/v3"
)

type (
Expand All @@ -17,7 +26,6 @@ func (tc *TestCalculator) Add(r *http.Request, args *AdditionArgs) int {

func (tc *TestCalculator) AddVoid(r *http.Request, args *AdditionArgs) {}

/*
func TestPotetoJSONRPCAdapterCall(t *testing.T) {
p := New()

Expand All @@ -35,7 +43,6 @@ func TestPotetoJSONRPCAdapterCall(t *testing.T) {
added := 10
add := 10
rpcClient := jsonrpc.NewClient("http://localhost:6000/add")
//result := &AdditionResult{}
result, err := rpcClient.Call(stdContext.Background(), "TestCalculator.Add", &AdditionArgs{Added: added, Add: add})
if err != nil {
t.Errorf("Unexpected error %v", err)
Expand All @@ -55,7 +62,6 @@ func TestPotetoJSONRPCAdapterCall(t *testing.T) {
}
}


func TestPotetoJSONRPCAdapterCallReturnVoid(t *testing.T) {
p := New()

Expand All @@ -73,7 +79,6 @@ func TestPotetoJSONRPCAdapterCallReturnVoid(t *testing.T) {
added := 10
add := 10
rpcClient := jsonrpc.NewClient("http://localhost:6001/add")
//result := &AdditionResult{}
result, err := rpcClient.Call(stdContext.Background(), "TestCalculator.AddVoid", &AdditionArgs{Added: added, Add: add})
if err != nil {
t.Errorf("Unexpected error %v", err)
Expand Down Expand Up @@ -187,5 +192,3 @@ func TestPotetoJSONRPCAdapter(t *testing.T) {
})
}
}

*/
Loading