-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinetaf.go
110 lines (105 loc) · 3.99 KB
/
inetaf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2021 Brad Fitzpatrick. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Serve inet.af
package main
import (
"io"
"net/http"
"strings"
)
func serveInetAf(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if r.Method != "GET" && r.Method != "HEAD" {
http.Error(w, "unsupported method", http.StatusMethodNotAllowed)
return
}
isGoGet := strings.Contains(r.RequestURI, "go-get=1") && r.URL.Query().Get("go-get") == "1"
if isGoGet {
if strings.HasPrefix(path, "/tcpproxy") {
io.WriteString(w, `<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="inet.af/tcpproxy git https://github.com/inetaf/tcpproxy">
<meta name="go-source" content="inet.af/tcpproxy https://github.com/inetaf/tcpproxy/ https://github.com/inetaf/tcpproxy/tree/master{/dir} https://github.com/inetaf/tcpproxy/blob/master{/dir}/{file}#L{line}">
</head>
</html>
`)
return
}
if strings.HasPrefix(path, "/netaddr") {
io.WriteString(w, `<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="inet.af/netaddr git https://github.com/inetaf/netaddr">
<meta name="go-source" content="inet.af/netaddr https://github.com/inetaf/netaddr/ https://github.com/inetaf/netaddr/tree/main{/dir} https://github.com/inetaf/netaddr/blob/main{/dir}/{file}#L{line}">
</head>
</html>
`)
return
}
if strings.HasPrefix(path, "/peercred") {
io.WriteString(w, `<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="inet.af/peercred git https://github.com/inetaf/peercred">
<meta name="go-source" content="inet.af/peercred https://github.com/inetaf/peercred/ https://github.com/inetaf/peercred/tree/main{/dir} https://github.com/inetaf/peercred/blob/main{/dir}/{file}#L{line}">
</head>
</html>
`)
return
}
if strings.HasPrefix(path, "/wf") {
io.WriteString(w, `<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="inet.af/wf git https://github.com/inetaf/wf">
<meta name="go-source" content="inet.af/wf https://github.com/inetaf/wf/ https://github.com/inetaf/wf/tree/main{/dir} https://github.com/inetaf/wf/blob/main{/dir}/{file}#L{line}">
</head>
</html>
`)
return
}
if strings.HasPrefix(path, "/netstack") {
io.WriteString(w, `<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="inet.af/netstack git https://github.com/inetaf/netstack">
<meta name="go-source" content="inet.af/netstack https://github.com/inetaf/netstack/ https://github.com/inetaf/netstack/tree/main{/dir} https://github.com/inetaf/netstack/blob/main{/dir}/{file}#L{line}">
</head>
</html>
`)
return
}
if path == "/" || strings.Contains(path, "/http") {
io.WriteString(w, `<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="inet.af git https://github.com/bradfitz/exp-httpclient">
<meta name="go-source" content="inet.af https://github.com/bradfitz/exp-httpclient/ https://github.com/bradfitz/exp-httpclient/tree/master{/dir} https://github.com/bradfitz/exp-httpclient/blob/master{/dir}/{file}#L{line}">
</head>
</html>
`)
}
return
}
if path == "/http" {
http.Redirect(w, r, "https://github.com/bradfitz/exp-httpclient", http.StatusFound)
return
}
if strings.HasPrefix(path, "/tcpproxy") ||
strings.HasPrefix(path, "/netaddr") ||
strings.HasPrefix(path, "/netstack") ||
strings.HasPrefix(path, "/peercred") ||
strings.HasPrefix(path, "/wf") {
http.Redirect(w, r, "https://pkg.go.dev/inet.af"+path, http.StatusFound)
return
}
if strings.Contains(path, "/http") {
target := "https://pkg.go.dev/inet.af" + path
http.Redirect(w, r, target, http.StatusFound)
return
}
const target = "http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/socket.h.html"
http.Redirect(w, r, target, http.StatusFound)
}