本文整理匯總了Golang中github.com/joewalnes/websocketd/libwebsocketd.Config.CgiDir方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.CgiDir方法的具體用法?Golang Config.CgiDir怎麽用?Golang Config.CgiDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/joewalnes/websocketd/libwebsocketd.Config
的用法示例。
在下文中一共展示了Config.CgiDir方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseCommandLine
func parseCommandLine() Config {
var mainConfig Config
var config libwebsocketd.Config
// If adding new command line options, also update the help text in help.go.
// The flag library's auto-generate help message isn't pretty enough.
// server config options
portFlag := flag.Int("port", 80, "HTTP port to listen on")
addressFlag := flag.String("address", "0.0.0.0", "Interface to bind to (e.g. 127.0.0.1)")
versionFlag := flag.Bool("version", false, "Print version and exit")
licenseFlag := flag.Bool("license", false, "Print license and exit")
logLevelFlag := flag.String("loglevel", "access", "Log level, one of: debug, trace, access, info, error, fatal")
// lib config options
basePathFlag := flag.String("basepath", "/", "Base URL path (e.g /)")
reverseLookupFlag := flag.Bool("reverselookup", true, "Perform reverse DNS lookups on remote clients")
scriptDirFlag := flag.String("dir", "", "Base directory for WebSocket scripts")
staticDirFlag := flag.String("staticdir", "", "Serve static content from this directory over HTTP")
cgiDirFlag := flag.String("cgidir", "", "Serve CGI scripts from this directory over HTTP")
devConsoleFlag := flag.Bool("devconsole", false, "Enable development console (cannot be used in conjunction with --staticdir)")
flag.Parse()
mainConfig.Addr = fmt.Sprintf("%s:%d", *addressFlag, *portFlag)
mainConfig.BasePath = *basePathFlag
switch *logLevelFlag {
case "debug":
mainConfig.LogLevel = libwebsocketd.LogDebug
break
case "trace":
mainConfig.LogLevel = libwebsocketd.LogTrace
break
case "access":
mainConfig.LogLevel = libwebsocketd.LogAccess
break
case "info":
mainConfig.LogLevel = libwebsocketd.LogInfo
break
case "error":
mainConfig.LogLevel = libwebsocketd.LogError
break
case "fatal":
mainConfig.LogLevel = libwebsocketd.LogFatal
break
default:
PrintHelp()
os.Exit(1)
}
config.ReverseLookup = *reverseLookupFlag
config.ScriptDir = *scriptDirFlag
config.StaticDir = *staticDirFlag
config.CgiDir = *cgiDirFlag
config.DevConsole = *devConsoleFlag
config.StartupTime = time.Now()
config.ServerSoftware = fmt.Sprintf("websocketd/%s", Version())
if len(os.Args) == 1 {
PrintHelp()
os.Exit(1)
}
if *versionFlag {
fmt.Printf("%s %s\n", filepath.Base(os.Args[0]), Version())
os.Exit(2)
}
if *licenseFlag {
fmt.Printf("%s %s\n", filepath.Base(os.Args[0]), Version())
fmt.Printf("%s\n", libwebsocketd.License)
os.Exit(2)
}
args := flag.Args()
if len(args) < 1 && config.ScriptDir == "" && config.StaticDir == "" && config.CgiDir == "" {
fmt.Fprintf(os.Stderr, "Please specify COMMAND or provide --dir, --staticdir or --cgidir argument.\n")
os.Exit(1)
}
if len(args) > 0 {
if config.ScriptDir != "" {
fmt.Fprintf(os.Stderr, "Ambiguous. Provided COMMAND and --dir argument. Please only specify just one.\n")
os.Exit(1)
}
config.CommandName = args[0]
config.CommandArgs = flag.Args()[1:]
config.UsingScriptDir = false
}
if len(config.ScriptDir) > 0 {
scriptDir, err := filepath.Abs(config.ScriptDir)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not resolve absolute path to dir '%s'.\n", config.ScriptDir)
os.Exit(1)
}
config.ScriptDir = scriptDir
config.UsingScriptDir = true
}
//.........這裏部分代碼省略.........
示例2: parseCommandLine
func parseCommandLine() *Config {
var mainConfig Config
var config libwebsocketd.Config
flag.Usage = func() {}
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
// If adding new command line options, also update the help text in help.go.
// The flag library's auto-generate help message isn't pretty enough.
addrlist := Arglist(make([]string, 0, 1)) // pre-reserve for 1 address
flag.Var(&addrlist, "address", "Interfaces to bind to (e.g. 127.0.0.1 or [::1]).")
// server config options
portFlag := flag.Int("port", 0, "HTTP port to listen on")
versionFlag := flag.Bool("version", false, "Print version and exit")
licenseFlag := flag.Bool("license", false, "Print license and exit")
logLevelFlag := flag.String("loglevel", "access", "Log level, one of: debug, trace, access, info, error, fatal")
sslFlag := flag.Bool("ssl", false, "Use TLS on listening socket (see also --sslcert and --sslkey)")
sslCert := flag.String("sslcert", "", "Should point to certificate PEM file when --ssl is used")
sslKey := flag.String("sslkey", "", "Should point to certificate private key file when --ssl is used")
maxForksFlag := flag.Int("maxforks", 0, "Max forks, zero means unlimited")
closeMsFlag := flag.Uint("closems", 0, "Time to start sending signals (0 never)")
redirPortFlag := flag.Int("redirport", 0, "HTTP port to redirect to canonical --port address")
// lib config options
binaryFlag := flag.Bool("binary", false, "Set websocketd to experimental binary mode (default is line by line)")
reverseLookupFlag := flag.Bool("reverselookup", false, "Perform reverse DNS lookups on remote clients")
scriptDirFlag := flag.String("dir", "", "Base directory for WebSocket scripts")
staticDirFlag := flag.String("staticdir", "", "Serve static content from this directory over HTTP")
cgiDirFlag := flag.String("cgidir", "", "Serve CGI scripts from this directory over HTTP")
devConsoleFlag := flag.Bool("devconsole", false, "Enable development console (cannot be used in conjunction with --staticdir)")
passEnvFlag := flag.String("passenv", defaultPassEnv[runtime.GOOS], "List of envvars to pass to subprocesses (others will be cleaned out)")
sameOriginFlag := flag.Bool("sameorigin", false, "Restrict upgrades if origin and host headers differ")
allowOriginsFlag := flag.String("origin", "", "Restrict upgrades if origin does not match the list")
headers := Arglist(make([]string, 0))
headersWs := Arglist(make([]string, 0))
headersHttp := Arglist(make([]string, 0))
flag.Var(&headers, "header", "Custom headers for any response.")
flag.Var(&headersWs, "header-ws", "Custom headers for successful WebSocket upgrade responses.")
flag.Var(&headersHttp, "header-http", "Custom headers for all but WebSocket upgrade HTTP responses.")
err := flag.CommandLine.Parse(os.Args[1:])
if err != nil {
if err == flag.ErrHelp {
PrintHelp()
os.Exit(0)
} else {
ShortHelp()
os.Exit(2)
}
}
port := *portFlag
if port == 0 {
if *sslFlag {
port = 443
} else {
port = 80
}
}
if socknum := len(addrlist); socknum != 0 {
mainConfig.Addr = make([]string, socknum)
for i, addrSingle := range addrlist {
mainConfig.Addr[i] = fmt.Sprintf("%s:%d", addrSingle, port)
}
} else {
mainConfig.Addr = []string{fmt.Sprintf(":%d", port)}
}
mainConfig.MaxForks = *maxForksFlag
mainConfig.RedirPort = *redirPortFlag
mainConfig.LogLevel = libwebsocketd.LevelFromString(*logLevelFlag)
if mainConfig.LogLevel == libwebsocketd.LogUnknown {
fmt.Printf("Incorrect loglevel flag '%s'. Use --help to see allowed values.\n", *logLevelFlag)
ShortHelp()
os.Exit(1)
}
config.Headers = []string(headers)
config.HeadersWs = []string(headersWs)
config.HeadersHTTP = []string(headersHttp)
config.CloseMs = *closeMsFlag
config.Binary = *binaryFlag
config.ReverseLookup = *reverseLookupFlag
config.Ssl = *sslFlag
config.ScriptDir = *scriptDirFlag
config.StaticDir = *staticDirFlag
config.CgiDir = *cgiDirFlag
config.DevConsole = *devConsoleFlag
config.StartupTime = time.Now()
config.ServerSoftware = fmt.Sprintf("websocketd/%s", Version())
if len(os.Args) == 1 {
fmt.Printf("Command line arguments are missing.\n")
ShortHelp()
os.Exit(1)
}
//.........這裏部分代碼省略.........