Skip to content

Commit

Permalink
Merge pull request #215 from poteto-go/20250126/fix-error-rpcut
Browse files Browse the repository at this point in the history
20250126/fix error rpcut
  • Loading branch information
poteto0 authored Jan 26, 2025
2 parents aec04fe + c79add9 commit afd0515
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
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) {
})
}
}
*/

0 comments on commit afd0515

Please sign in to comment.