本文整理匯總了Golang中github.com/cortesi/devd.Devd.Serve方法的典型用法代碼示例。如果您正苦於以下問題:Golang Devd.Serve方法的具體用法?Golang Devd.Serve怎麽用?Golang Devd.Serve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cortesi/devd.Devd
的用法示例。
在下文中一共展示了Devd.Serve方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
//.........這裏部分代碼省略.........
).
PlaceHolder("N").
Short('u').
Default("0").
Uint()
watch := kingpin.Flag("watch", "Watch path to trigger livereload").
PlaceHolder("PATH").
Short('w').
Strings()
excludes := kingpin.Flag("exclude", "Glob pattern for files to exclude from livereload").
PlaceHolder("PATTERN").
Short('x').
Strings()
debug := kingpin.Flag("debug", "Debugging for devd development").
Default("false").
Bool()
routes := kingpin.Arg(
"route",
`Routes have the following forms:
[SUBDOMAIN]/<PATH>=<DIR>
[SUBDOMAIN]/<PATH>=<URL>
<DIR>
<URL>
`,
).Required().Strings()
kingpin.Version(devd.Version)
kingpin.Parse()
realAddr := *address
if *allInterfaces {
realAddr = "0.0.0.0"
}
var creds *devd.Credentials
if *credspec != "" {
var err error
creds, err = devd.CredentialsFromSpec(*credspec)
if err != nil {
kingpin.Fatalf("%s", err)
return
}
}
dd := devd.Devd{
// Shaping
Latency: *latency,
DownKbps: *downKbps,
UpKbps: *upKbps,
// Livereload
LivereloadRoutes: *livereloadRoutes,
WatchPaths: *watch,
Excludes: *excludes,
Credentials: creds,
}
if err := dd.AddRoutes(*routes); err != nil {
kingpin.Fatalf("%s", err)
}
if err := dd.AddIgnores(*ignoreLogs); err != nil {
kingpin.Fatalf("%s", err)
}
logger := termlog.NewLog()
if *quiet {
logger.Quiet()
}
if *debug {
logger.Enable("debug")
}
if *logTime {
logger.Enable("timer")
}
if *logHeaders {
logger.Enable("headers")
}
err := dd.Serve(
realAddr,
*port,
*certFile,
logger,
func(url string) {
if *openBrowser {
webbrowser.Open(url)
}
},
)
if err != nil {
kingpin.Fatalf("%s", err)
}
}
示例2: main
func main() {
address := kingpin.Flag("address", "Address to listen on").
Short('A').
Default("127.0.0.1").
String()
allInterfaces := kingpin.Flag("all", "Listen on all addresses").
Short('a').
Bool()
certFile := kingpin.Flag("cert", "Certificate bundle file - enables TLS").
Short('c').
PlaceHolder("PATH").
ExistingFile()
forceColor := kingpin.Flag("color", "Enable colour output, even if devd is not connected to a terminal").
Short('C').
Bool()
downKbps := kingpin.Flag(
"down",
"Throttle downstream from the client to N kilobytes per second",
).
PlaceHolder("N").
Short('d').
Default("0").
Uint()
logHeaders := kingpin.Flag("logheaders", "Log headers").
Short('H').
Default("false").
Bool()
ignoreLogs := kingpin.Flag(
"ignore",
"Disable logging matching requests. Regexes are matched over 'host/path'",
).
Short('I').
PlaceHolder("REGEX").
Strings()
livereloadNaked := kingpin.Flag("livereload", "Enable livereload").
Short('L').
Default("false").
Bool()
livereloadRoutes := kingpin.Flag("livewatch", "Enable livereload and watch for static file changes").
Short('l').
Default("false").
Bool()
moddMode := kingpin.Flag("modd", "Modd is our parent - synonym for -LCt").
Short('m').
Bool()
latency := kingpin.Flag("latency", "Add N milliseconds of round-trip latency").
PlaceHolder("N").
Short('n').
Default("0").
Int()
openBrowser := kingpin.Flag("open", "Open browser window on startup").
Short('o').
Default("false").
Bool()
port := kingpin.Flag(
"port",
"Port to listen on - if not specified, devd will auto-pick a sensible port",
).
Short('p').
Int()
credspec := kingpin.Flag(
"password",
"HTTP basic password protection",
).
PlaceHolder("USER:PASS").
Short('P').
String()
quiet := kingpin.Flag("quiet", "Silence all logs").
Short('q').
Default("false").
Bool()
tls := kingpin.Flag("tls", "Serve TLS with auto-generated self-signed certificate (~/.devd.crt)").
Short('s').
Default("false").
Bool()
noTimestamps := kingpin.Flag("notimestamps", "Disable timestamps in output").
Short('t').
Default("false").
Bool()
logTime := kingpin.Flag("logtime", "Log timing").
Short('T').
Default("false").
Bool()
//.........這裏部分代碼省略.........
示例3: main
//.........這裏部分代碼省略.........
Strings()
livereloadRoutes := kingpin.Flag("livereload", "Enable livereload for static files").
Short('l').
Default("false").
Bool()
latency := kingpin.Flag("latency", "Add N milliseconds of round-trip latency").
PlaceHolder("N").
Short('n').
Default("0").
Int()
openBrowser := kingpin.Flag("open", "Open browser window on startup").
Short('o').
Default("false").
Bool()
port := kingpin.Flag(
"port",
"Port to listen on - if not specified, devd will auto-pick a sensible port",
).
Short('p').
Int()
logTime := kingpin.Flag("logtime", "Log timing").
Short('T').
Default("false").
Bool()
upKbps := kingpin.Flag(
"up",
"Throttle upstream from the client to N kilobytes per second",
).
PlaceHolder("N").
Short('u').
Default("0").
Uint()
watch := kingpin.Flag("watch", "Watch path to trigger livereload").
PlaceHolder("PATH").
Short('w').
Strings()
debug := kingpin.Flag("debug", "Debugging for devd development").
Default("false").
Bool()
excludes := kingpin.Flag("exclude", "Glob pattern for files to exclude from livereload.").
PlaceHolder("PATTERN").
Short('x').
Strings()
routes := kingpin.Arg(
"route",
`Routes have the following forms:
[SUBDOMAIN]/<PATH>=<DIR>
[SUBDOMAIN]/<PATH>=<URL>
<DIR>
<URL>
`,
).Required().Strings()
kingpin.Version(devd.Version)
kingpin.Parse()
realAddr := *address
if *allInterfaces {
realAddr = "0.0.0.0"
}
dd := devd.Devd{
Routes: *routes,
OpenBrowser: *openBrowser,
CertFile: *certFile,
Address: realAddr,
Port: *port,
// Shaping
Latency: *latency,
DownKbps: *downKbps,
UpKbps: *upKbps,
// Livereload
LivereloadRoutes: *livereloadRoutes,
Watch: *watch,
Excludes: *excludes,
// Logging
Debug: *debug,
LogHeaders: *logHeaders,
LogTime: *logTime,
IgnoreLogs: *ignoreLogs,
}
err := dd.Serve()
if err != nil {
kingpin.Fatalf("%s", err)
}
}