Skip to content

Commit c55cc24

Browse files
create transport package
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
1 parent b922133 commit c55cc24

12 files changed

Lines changed: 25 additions & 22 deletions

File tree

v2/examples_v1/echo/echo_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
papiv1 "github.com/gotify/plugin-api"
1616
"github.com/gotify/plugin-api/v2"
1717
"github.com/gotify/plugin-api/v2/generated/protobuf"
18+
"github.com/gotify/plugin-api/v2/transport"
1819
"google.golang.org/grpc"
1920
"google.golang.org/grpc/credentials"
2021
"google.golang.org/protobuf/types/known/emptypb"
@@ -23,16 +24,16 @@ import (
2324
func TestEcho(t *testing.T) {
2425
pluginInfo := GetGotifyPluginInfo()
2526

26-
client, err := plugin.NewEphemeralTLSClient()
27+
client, err := transport.NewEphemeralTLSClient()
2728
if err != nil {
2829
t.Fatal(err)
2930
}
3031

3132
var reqRx, reqTx uintptr
3233
var respRx, respTx uintptr
3334

34-
plugin.NewAnonPipe(&reqRx, &reqTx, true)
35-
plugin.NewAnonPipe(&respRx, &respTx, true)
35+
transport.NewAnonPipe(&reqRx, &reqTx, true)
36+
transport.NewAnonPipe(&respRx, &respTx, true)
3637

3738
go func() {
3839
reqFileRx := os.NewFile(reqRx, fmt.Sprintf("/proc/self/fd/%d", reqRx))
@@ -57,7 +58,7 @@ func TestEcho(t *testing.T) {
5758
t.Fatal(err)
5859
}
5960

60-
listener, addr, err := plugin.NewListener()
61+
listener, addr, err := transport.NewListener()
6162
if err != nil {
6263
t.Fatal(err)
6364
}
@@ -175,7 +176,7 @@ func TestEcho(t *testing.T) {
175176
t.Fatal("expected ", "Echo plugin running at: https://gotify.example.com/plugin/echo-test/echo", " got ", displayResponse.GetMarkdown())
176177
}
177178

178-
tlsWebhookName := plugin.BuildPluginTLSName(plugin.PurposePluginWebhook, pluginInfo.ModulePath)
179+
tlsWebhookName := transport.BuildPluginTLSName(transport.PurposePluginWebhook, pluginInfo.ModulePath)
179180

180181
for range 3 {
181182
testreq := httptest.NewRequest("GET", "https://"+tlsWebhookName+"/plugin/echo-test/echo", nil)

v2/examples_v1/minimal/minimal_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
papiv1 "github.com/gotify/plugin-api"
1212
"github.com/gotify/plugin-api/v2"
1313
"github.com/gotify/plugin-api/v2/generated/protobuf"
14+
"github.com/gotify/plugin-api/v2/transport"
1415
"google.golang.org/grpc"
1516
"google.golang.org/grpc/credentials"
1617
"google.golang.org/protobuf/types/known/emptypb"
@@ -19,16 +20,16 @@ import (
1920
func testEchoImpl(t *testing.T, listener net.Listener, addr string) {
2021
pluginInfo := GetGotifyPluginInfo()
2122

22-
client, err := plugin.NewEphemeralTLSClient()
23+
client, err := transport.NewEphemeralTLSClient()
2324
if err != nil {
2425
t.Fatal(err)
2526
}
2627

2728
var reqRx, reqTx uintptr
2829
var respRx, respTx uintptr
2930

30-
plugin.NewAnonPipe(&reqRx, &reqTx, true)
31-
plugin.NewAnonPipe(&respRx, &respTx, true)
31+
transport.NewAnonPipe(&reqRx, &reqTx, true)
32+
transport.NewAnonPipe(&respRx, &respTx, true)
3233

3334
go func() {
3435
reqFileRx := os.NewFile(reqRx, fmt.Sprintf("/proc/self/fd/%d", reqRx))
@@ -109,15 +110,15 @@ func testEchoImpl(t *testing.T, listener net.Listener, addr string) {
109110
}
110111

111112
func TestEcho(t *testing.T) {
112-
listener, addr, err := plugin.NewListener()
113+
listener, addr, err := transport.NewListener()
113114
if err != nil {
114115
t.Fatal(err)
115116
}
116117
testEchoImpl(t, listener, addr)
117118
}
118119

119120
func TestEchoTCP(t *testing.T) {
120-
listener, addr, err := plugin.NewTCPListener()
121+
listener, addr, err := transport.NewTCPListener()
121122
if err != nil {
122123
t.Fatal(err)
123124
}

v2/shim_v1.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/gin-gonic/gin"
2929
papiv1 "github.com/gotify/plugin-api"
3030
"github.com/gotify/plugin-api/v2/generated/protobuf"
31+
"github.com/gotify/plugin-api/v2/transport"
3132
)
3233

3334
type GrpcDialer interface {
@@ -106,7 +107,7 @@ func NewCompatV1Rpc(compatV1 *CompatV1, cliArgs []string) (*CompatV1Shim, error)
106107
}
107108
csrBytes, err := x509.CreateCertificateRequest(rand.Reader, &x509.CertificateRequest{
108109
Subject: pkix.Name{
109-
CommonName: BuildPluginTLSName("*", pluginInfo.ModulePath),
110+
CommonName: transport.BuildPluginTLSName("*", pluginInfo.ModulePath),
110111
},
111112
}, priv)
112113

@@ -204,7 +205,7 @@ func (h *CompatV1Shim) ServeHTTP(w http.ResponseWriter, r *http.Request) {
204205
return
205206
}
206207

207-
pluginRpcHostName := BuildPluginTLSName(PurposePluginRPC, h.pluginInfo.ModulePath)
208+
pluginRpcHostName := transport.BuildPluginTLSName(transport.PurposePluginRPC, h.pluginInfo.ModulePath)
208209

209210
if r.TLS.ServerName == pluginRpcHostName {
210211
if r.ProtoMajor != 2 {
@@ -220,7 +221,7 @@ func (h *CompatV1Shim) ServeHTTP(w http.ResponseWriter, r *http.Request) {
220221
return
221222
}
222223

223-
pluginWebhookHostName := BuildPluginTLSName(PurposePluginWebhook, h.pluginInfo.ModulePath)
224+
pluginWebhookHostName := transport.BuildPluginTLSName(transport.PurposePluginWebhook, h.pluginInfo.ModulePath)
224225
if r.TLS.ServerName == pluginWebhookHostName {
225226
h.gin.ServeHTTP(w, r)
226227
return
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build unix
22

3-
package plugin
3+
package transport
44

55
import (
66
"golang.org/x/sys/unix"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build windows
22

3-
package plugin
3+
package transport
44

55
import (
66
"unsafe"

v2/pipe_net.go renamed to v2/transport/pipe_net.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package plugin
1+
package transport
22

33
import (
44
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package plugin
1+
package transport
22

33
import (
44
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build !unix
22

3-
package plugin
3+
package transport
44

55
import (
66
"net"

v2/pipe_tcp.go renamed to v2/transport/pipe_tcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package plugin
1+
package transport
22

33
import (
44
"fmt"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//go:build unix
22

3-
package plugin
3+
package transport
44

55
import (
66
"fmt"

0 commit comments

Comments
 (0)