-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservers.go
46 lines (39 loc) Β· 1.06 KB
/
servers.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
package web_container_proxy
// ζ ΈεΏδ»£η ε
ε«ιζζε‘ε¨οΌζδ»Άδ»₯ει‘΅ι’οΌ εε代η
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
)
func ReverseProxyServer(uri string) http.Handler {
dest, _ := url.Parse(addProtocol(uri))
return httputil.NewSingleHostReverseProxy(dest)
}
func newStaticServer(uri string, hasCustom404 bool, custom404 string) http.Handler {
log.Println("newStaticServer is 1" + uri)
return &StaticServer{http.FileServer(http.Dir(GetCurrPath() + uri)), hasCustom404, custom404}
}
func GetCurrPath() string {
file, _ := exec.LookPath(os.Args[0])
path, _ := filepath.Abs(file)
index := strings.LastIndex(path, string(os.PathSeparator))
ret := path[:index]
return ret
}
func newSingleFileServer(uri string) http.Handler {
log.Println("newSingleFileServer is 2" + uri)
return &SingleFileServer{uri}
}
func addProtocol(url string) string {
if matches, _ := regexp.MatchString("^\\w+://", url); !matches {
return fmt.Sprintf("http://%s", url)
}
return url
}