代码拉取完成,页面将自动刷新
// Package vodka is a high productive and modular web framework in Golang.
package vodka
import (
"log"
"os"
"runtime"
"strconv"
"strings"
)
func (m *Vodka) Listen(args ...interface{}) {
addr := GetAddress(args...)
if runtime.NumCPU() > 1 {
runtime.GOMAXPROCS(runtime.NumCPU())
} else {
runtime.GOMAXPROCS(runtime.NumCPU() * 4)
}
m.DoActionHook("VodkaListen")
m.Server.Addr = addr
log.Fatal(m.Server.ListenAndServe())
}
func (m *Vodka) ListenTLS(certFile, keyFile string, args ...interface{}) {
addr := GetAddress(args...)
if runtime.NumCPU() > 1 {
runtime.GOMAXPROCS(runtime.NumCPU())
} else {
runtime.GOMAXPROCS(runtime.NumCPU() * 4)
}
m.DoActionHook("VodkaListenTLS")
m.Server.Addr = addr
log.Fatal(m.Server.ListenAndServeTLS(certFile, keyFile))
}
func GetAddress(args ...interface{}) string {
var host string
var port int
if len(args) == 1 {
switch arg := args[0].(type) {
case string:
addrs := strings.Split(args[0].(string), ":")
if len(addrs) == 1 {
host = addrs[0]
} else if len(addrs) >= 2 {
host = addrs[0]
_port, _ := strconv.ParseInt(addrs[1], 10, 0)
port = int(_port)
}
case int:
port = arg
case int64:
port = int(arg)
}
} else if len(args) >= 2 {
if arg, ok := args[0].(string); ok {
host = arg
}
if arg, ok := args[1].(int); ok {
port = arg
}
}
if iHost := os.Getenv("HOST"); len(iHost) != 0 {
host = iHost
} else if len(host) == 0 {
host = "0.0.0.0"
}
if iPort, _ := strconv.ParseInt(os.Getenv("PORT"), 10, 32); iPort != 0 {
port = int(iPort)
} else if port == 0 {
port = 8000
}
addr := host + ":" + strconv.FormatInt(int64(port), 10)
return addr
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。