Repository: line/line-bot-sdk-go
Pull request #397 (2023-11-22 14:31:29)

Modify endpoint URL generation in Url function
Fix https://github.com/line/line-bot-sdk-go/issues/396

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/line/line-bot-sdk-go/pull/397?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=line) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`f530088`)](https://app.codecov.io/gh/line/line-bot-sdk-go/commit/f530088925975e04c02c2ef7071469ec326a022d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=line) 55.75% compared to head [(`283d9e2`)](https://app.codecov.io/gh/line/line-bot-sdk-go/pull/397?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=line) 55.75%.

> :exclamation: Current head 283d9e2 differs from pull request most recent head 50e6fd1. Consider uploading reports for the commit 50e6fd1 to get more accurate results


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #397   +/-   ##
=======================================
  Coverage   55.75%   55.75%           
=======================================
  Files          86       86           
  Lines        5406     5406           
=======================================
  Hits         3014     3014           
  Misses       2172     2172           
  Partials      220      220           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/line/line-bot-sdk-go/pull/397?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=line).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=line).


Patch:
diff --git a/generator/src/main/resources/line-bot-sdk-go-generator/api.pebble b/generator/src/main/resources/line-bot-sdk-go-generator/api.pebble
index 00fd936..64aee51 100644
--- a/generator/src/main/resources/line-bot-sdk-go-generator/api.pebble
+++ b/generator/src/main/resources/line-bot-sdk-go-generator/api.pebble
@@ -88,8 +88,9 @@ func (client *{{ classname }}) Do(req *http.Request) (*http.Response, error) {
 }
 
 func (client *{{ classname }}) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/channel_access_token/api_channel_access_token.go b/linebot/channel_access_token/api_channel_access_token.go
index ab46acf..fe8b9d9 100644
--- a/linebot/channel_access_token/api_channel_access_token.go
+++ b/linebot/channel_access_token/api_channel_access_token.go
@@ -78,8 +78,9 @@ func (client *ChannelAccessTokenAPI) Do(req *http.Request) (*http.Response, erro
 }
 
 func (client *ChannelAccessTokenAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/insight/api_insight.go b/linebot/insight/api_insight.go
index 442d848..f408cfe 100644
--- a/linebot/insight/api_insight.go
+++ b/linebot/insight/api_insight.go
@@ -88,8 +88,9 @@ func (client *InsightAPI) Do(req *http.Request) (*http.Response, error) {
 }
 
 func (client *InsightAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/liff/api_liff.go b/linebot/liff/api_liff.go
index d0620d5..fe8dcfd 100644
--- a/linebot/liff/api_liff.go
+++ b/linebot/liff/api_liff.go
@@ -89,8 +89,9 @@ func (client *LiffAPI) Do(req *http.Request) (*http.Response, error) {
 }
 
 func (client *LiffAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/manage_audience/api_manage_audience.go b/linebot/manage_audience/api_manage_audience.go
index f005f64..f5aa7c3 100644
--- a/linebot/manage_audience/api_manage_audience.go
+++ b/linebot/manage_audience/api_manage_audience.go
@@ -90,8 +90,9 @@ func (client *ManageAudienceAPI) Do(req *http.Request) (*http.Response, error) {
 }
 
 func (client *ManageAudienceAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/manage_audience/api_manage_audience_blob.go b/linebot/manage_audience/api_manage_audience_blob.go
index 4a35f3b..24ee0ae 100644
--- a/linebot/manage_audience/api_manage_audience_blob.go
+++ b/linebot/manage_audience/api_manage_audience_blob.go
@@ -91,8 +91,9 @@ func (client *ManageAudienceBlobAPI) Do(req *http.Request) (*http.Response, erro
 }
 
 func (client *ManageAudienceBlobAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/messaging_api/api_messaging_api.go b/linebot/messaging_api/api_messaging_api.go
index 61505ce..a501f1c 100644
--- a/linebot/messaging_api/api_messaging_api.go
+++ b/linebot/messaging_api/api_messaging_api.go
@@ -89,8 +89,9 @@ func (client *MessagingApiAPI) Do(req *http.Request) (*http.Response, error) {
 }
 
 func (client *MessagingApiAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/messaging_api/api_messaging_api_blob.go b/linebot/messaging_api/api_messaging_api_blob.go
index 5b3172f..ae2cc18 100644
--- a/linebot/messaging_api/api_messaging_api_blob.go
+++ b/linebot/messaging_api/api_messaging_api_blob.go
@@ -89,8 +89,9 @@ func (client *MessagingApiBlobAPI) Do(req *http.Request) (*http.Response, error)
 }
 
 func (client *MessagingApiBlobAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/module/api_line_module.go b/linebot/module/api_line_module.go
index 5e58f09..0d35e02 100644
--- a/linebot/module/api_line_module.go
+++ b/linebot/module/api_line_module.go
@@ -89,8 +89,9 @@ func (client *LineModuleAPI) Do(req *http.Request) (*http.Response, error) {
 }
 
 func (client *LineModuleAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/module_attach/api_line_module_attach.go b/linebot/module_attach/api_line_module_attach.go
index b502d7b..94939c7 100644
--- a/linebot/module_attach/api_line_module_attach.go
+++ b/linebot/module_attach/api_line_module_attach.go
@@ -88,8 +88,9 @@ func (client *LineModuleAttachAPI) Do(req *http.Request) (*http.Response, error)
 }
 
 func (client *LineModuleAttachAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 
diff --git a/linebot/shop/api_shop.go b/linebot/shop/api_shop.go
index 59fe115..a6685d9 100644
--- a/linebot/shop/api_shop.go
+++ b/linebot/shop/api_shop.go
@@ -88,8 +88,9 @@ func (client *ShopAPI) Do(req *http.Request) (*http.Response, error) {
 }
 
 func (client *ShopAPI) Url(endpointPath string) string {
-	u := client.endpoint
-	u.Path = path.Join(u.Path, endpointPath)
+	newPath := path.Join(client.endpoint.Path, endpointPath)
+	u := *client.endpoint
+	u.Path = newPath
 	return u.String()
 }
 


Test patch:
diff --git a/linebot/messaging_api/tests/handwritten/calling_api_twice_test.go b/linebot/messaging_api/tests/handwritten/calling_api_twice_test.go
new file mode 100644
index 0000000..ab2cac3
--- /dev/null
+++ b/linebot/messaging_api/tests/handwritten/calling_api_twice_test.go
@@ -0,0 +1,50 @@
+package tests
+
+import (
+	"net/http"
+	"net/http/httptest"
+	"testing"
+
+	"github.com/line/line-bot-sdk-go/v8/linebot/messaging_api"
+)
+
+func TestCallingAPITwice(t *testing.T) {
+	server := httptest.NewServer(
+		http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+			if r.URL.Path != "/v2/bot/message/push" {
+				t.Errorf("Expected path '/v2/bot/message/push', but got '%s'", r.URL.Path)
+			}
+			w.Header().Add("X-Line-Request-Id", "1234567890")
+			w.Write([]byte(`{}`))
+		}),
+	)
+	client, err := messaging_api.NewMessagingApiAPI(
+		"channelToken",
+		messaging_api.WithEndpoint(server.URL),
+	)
+	if err != nil {
+		t.Fatalf("Failed to create client: %v", err)
+	}
+	_, err = client.PushMessage(&messaging_api.PushMessageRequest{
+		Messages: []messaging_api.MessageInterface{
+			&messaging_api.TextMessage{
+				Text: "Hello, world",
+			},
+		},
+	}, "")
+	if err != nil {
+		t.Fatalf("Failed to get response: %v", err)
+	}
+
+	// call again
+	_, err = client.PushMessage(&messaging_api.PushMessageRequest{
+		Messages: []messaging_api.MessageInterface{
+			&messaging_api.TextMessage{
+				Text: "Hello, world",
+			},
+		},
+	}, "")
+	if err != nil {
+		t.Fatalf("Failed to get response: %v", err)
+	}
+}