在Go中使用未导出的函数

Docs

 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
package handler

import (
	"net/http"
	"os"
	"strings"
	_ "unsafe"

	_ "github.com/hoppscotch/proxyscotch/libproxy"
)

//go:linkname proxyHandler github.com/hoppscotch/proxyscotch/libproxy.proxyHandler
func proxyHandler(w http.ResponseWriter, r *http.Request)

//go:linkname accessToken github.com/hoppscotch/proxyscotch/libproxy.accessToken
var accessToken string

//go:linkname allowedOrigins github.com/hoppscotch/proxyscotch/libproxy.allowedOrigins
var allowedOrigins []string

//go:linkname bannedOutputs github.com/hoppscotch/proxyscotch/libproxy.bannedOutputs
var bannedOutputs []string

//go:linkname bannedDests github.com/hoppscotch/proxyscotch/libproxy.bannedDests
var bannedDests []string

func Handler(w http.ResponseWriter, r *http.Request) {
	if os.Getenv("ACCESS_TOKEN") != "" {
		accessToken = os.Getenv("ACCESS_TOKEN")
	}
	if os.Getenv("ALLOWED_ORIGINS") != "" {
		allowedOrigins = strings.Split(os.Getenv("ALLOWED_ORIGINS"), ",")
	} else {
		allowedOrigins = []string{"*"}
	}
	if os.Getenv("BANNED_OUTPUTS") != "" {
		bannedOutputs = strings.Split(os.Getenv("BANNED_OUTPUTS"), ",")
	}
	if os.Getenv("BANNED_DESTINATIONS") != "" {
		bannedDests = strings.Split(os.Getenv("BANNED_DESTINATIONS"), ",")
	}
	proxyHandler(w, r)
}
除非另有说明,此内容使用 CC BY-SA 4.0 许可。
提交: 5a1bbd02   环境: production   Hugo: 0.139.3   时间: 1733917433357452
作者对于因使用或解读所提供内容而导致的任何直接或间接后果不承担任何责任。
使用 Hugo 构建
主题 StackJimmy 设计