@@ -13,7 +13,12 @@ go get github.com/anthhub/forwarder
1313## Usage
1414
1515``` go
16- options := []*Option{
16+
17+ import (
18+ " github.com/anthhub/forwarder"
19+ )
20+
21+ options := []*forwarder.Option {
1722 {
1823 // the local port for forwarding
1924 LocalPort: 8080 ,
@@ -28,33 +33,37 @@ go get github.com/anthhub/forwarder
2833 },
2934 },
3035 {
31- LocalPort: 8081 ,
36+ // if local port isn't provided, forwarder will generate a random port number
37+ // LocalPort: 8081,
3238 PodPort: 80 ,
33- Pod: v1.Pod {
39+ // the k8s service metadata, it's to forward service
40+ Service: v1.Service {
3441 ObjectMeta: metav1.ObjectMeta {
35- Name: " nginx-deployment-66b6c48dd5-n86z4" ,
36- Namespace: " default" ,
42+ Name: " my-nginx-svc" ,
43+ // the namespace default is "default"
44+ // Namespace: "default",
3745 },
3846 },
3947 },
4048 }
4149
42- // create a forwarder
43- ret , err := WithForwarders (context.Background (), options, * kubecfg)
50+ // it's to create a forwarder, and you need provide a path of kubeconfig
51+ ret , err := forwarder. WithForwarders (context.Background (), options, " ./ kubecfg" )
4452 if err != nil {
4553 panic (err)
4654 }
4755 // remember to close the forwarding
4856 defer ret.Close ()
49- // wait the ready of forwarding
50- ret.Ready ()
57+ // wait forwarding ready
58+ // the remote and local ports are listed
59+ ports , err := ret.Ready ()
60+ if err != nil {
61+ panic (err)
62+ }
5163 // ...
5264
5365 // if you want to block the goroutine and listen IOStreams close signal, you can do as following:
54- //
55- // if err := ret.Wait(); err != nil {
56- // panic(err)
57- // }
66+ ret.Wait ()
5867```
5968
6069> If you want to learn more about ` forwarder ` , you can read test cases and source code.
0 commit comments