MCPcopy Index your code
hub / github.com/tailscale/tailscale / main

Function main

cmd/pgproxy/pgproxy.go:42–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40)
41
42func main() {
43 flag.Parse()
44 if *hostname == "" {
45 log.Fatal("missing --hostname")
46 }
47 if *upstreamAddr == "" {
48 log.Fatal("missing --upstream-addr")
49 }
50 if *upstreamCA == "" {
51 log.Fatal("missing --upstream-ca-file")
52 }
53 if *tailscaleDir == "" {
54 log.Fatal("missing --state-dir")
55 }
56
57 ts := &tsnet.Server{
58 Dir: *tailscaleDir,
59 Hostname: *hostname,
60 }
61
62 if os.Getenv("TS_AUTHKEY") == "" {
63 log.Print("Note: you need to run this with TS_AUTHKEY=... the first time, to join your tailnet of choice.")
64 }
65
66 tsclient, err := ts.LocalClient()
67 if err != nil {
68 log.Fatalf("getting tsnet API client: %v", err)
69 }
70
71 p, err := newProxy(*upstreamAddr, *upstreamCA, tsclient)
72 if err != nil {
73 log.Fatal(err)
74 }
75 expvar.Publish("pgproxy", p.Expvar())
76
77 if *debugPort != 0 {
78 mux := http.NewServeMux()
79 tsweb.Debugger(mux)
80 srv := &http.Server{
81 Handler: mux,
82 }
83 dln, err := ts.Listen("tcp", fmt.Sprintf(":%d", *debugPort))
84 if err != nil {
85 log.Fatal(err)
86 }
87 go func() {
88 log.Fatal(srv.Serve(dln))
89 }()
90 }
91
92 ln, err := ts.Listen("tcp", fmt.Sprintf(":%d", *port))
93 if err != nil {
94 log.Fatal(err)
95 }
96 log.Printf("serving access to %s on port %d", *upstreamAddr, *port)
97 log.Fatal(p.Serve(ln))
98}
99

Callers

nothing calls this directly

Calls 12

LocalClientMethod · 0.95
ListenMethod · 0.95
ServeMethod · 0.95
DebuggerFunction · 0.92
newProxyFunction · 0.85
ExpvarMethod · 0.80
PrintfMethod · 0.80
FatalMethod · 0.65
FatalfMethod · 0.65
ParseMethod · 0.45
PublishMethod · 0.45
ServeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…