tsnet: make ListenService examples consistent with other tsnet examples
Fixes tailscale/corp#36365 Signed-off-by: Harry Harpham <harry@tailscale.com>
This commit is contained in:
@@ -19,21 +19,19 @@ import (
|
|||||||
// Service on multiple ports. In this example, we run an HTTPS server on 443 and
|
// Service on multiple ports. In this example, we run an HTTPS server on 443 and
|
||||||
// an HTTP server handling pprof requests to the same runtime on 6060.
|
// an HTTP server handling pprof requests to the same runtime on 6060.
|
||||||
func ExampleServer_ListenService_multiplePorts() {
|
func ExampleServer_ListenService_multiplePorts() {
|
||||||
s := &tsnet.Server{
|
srv := &tsnet.Server{
|
||||||
Hostname: "tsnet-services-demo",
|
Hostname: "shu",
|
||||||
}
|
}
|
||||||
defer s.Close()
|
|
||||||
|
|
||||||
ln, err := s.ListenService("svc:my-service", tsnet.ServiceModeHTTP{
|
ln, err := srv.ListenService("svc:my-service", tsnet.ServiceModeHTTP{
|
||||||
HTTPS: true,
|
HTTPS: true,
|
||||||
Port: 443,
|
Port: 443,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer ln.Close()
|
|
||||||
|
|
||||||
pprofLn, err := s.ListenService("svc:my-service", tsnet.ServiceModeTCP{
|
pprofLn, err := srv.ListenService("svc:my-service", tsnet.ServiceModeTCP{
|
||||||
Port: 6060,
|
Port: 6060,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -205,19 +205,17 @@ func ExampleServer_ListenFunnel_funnelOnly() {
|
|||||||
|
|
||||||
// ExampleServer_ListenService demonstrates how to advertise an HTTPS Service.
|
// ExampleServer_ListenService demonstrates how to advertise an HTTPS Service.
|
||||||
func ExampleServer_ListenService() {
|
func ExampleServer_ListenService() {
|
||||||
s := &tsnet.Server{
|
srv := &tsnet.Server{
|
||||||
Hostname: "tsnet-services-demo",
|
Hostname: "atum",
|
||||||
}
|
}
|
||||||
defer s.Close()
|
|
||||||
|
|
||||||
ln, err := s.ListenService("svc:my-service", tsnet.ServiceModeHTTP{
|
ln, err := srv.ListenService("svc:my-service", tsnet.ServiceModeHTTP{
|
||||||
HTTPS: true,
|
HTTPS: true,
|
||||||
Port: 443,
|
Port: 443,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer ln.Close()
|
|
||||||
|
|
||||||
log.Printf("Listening on https://%v\n", ln.FQDN)
|
log.Printf("Listening on https://%v\n", ln.FQDN)
|
||||||
log.Fatal(http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
log.Fatal(http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -238,19 +236,17 @@ func ExampleServer_ListenService_reverseProxy() {
|
|||||||
Host: targetAddress,
|
Host: targetAddress,
|
||||||
})
|
})
|
||||||
|
|
||||||
s := &tsnet.Server{
|
srv := &tsnet.Server{
|
||||||
Hostname: "tsnet-services-demo",
|
Hostname: "tefnut",
|
||||||
}
|
}
|
||||||
defer s.Close()
|
|
||||||
|
|
||||||
ln, err := s.ListenService("svc:my-service", tsnet.ServiceModeHTTP{
|
ln, err := srv.ListenService("svc:my-service", tsnet.ServiceModeHTTP{
|
||||||
HTTPS: true,
|
HTTPS: true,
|
||||||
Port: 443,
|
Port: 443,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer ln.Close()
|
|
||||||
|
|
||||||
log.Printf("Listening on https://%v\n", ln.FQDN)
|
log.Printf("Listening on https://%v\n", ln.FQDN)
|
||||||
log.Fatal(http.Serve(ln, reverseProxy))
|
log.Fatal(http.Serve(ln, reverseProxy))
|
||||||
|
|||||||
Reference in New Issue
Block a user