本文整理汇总了Golang中github.com/cortesi/termlog.Logger.Shout方法的典型用法代码示例。如果您正苦于以下问题:Golang Logger.Shout方法的具体用法?Golang Logger.Shout怎么用?Golang Logger.Shout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cortesi/termlog.Logger
的用法示例。
在下文中一共展示了Logger.Shout方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Serve
// Serve starts the devd server. The callback is called with the serving URL
// just before service starts.
func (dd *Devd) Serve(address string, port int, certFile string, logger termlog.Logger, callback func(string)) error {
templates, err := ricetemp.MakeTemplates(rice.MustFindBox("templates"))
if err != nil {
return fmt.Errorf("Error loading templates: %s", err)
}
mux, err := dd.Router(logger, templates)
if err != nil {
return err
}
var tlsConfig *tls.Config
var tlsEnabled bool
if certFile != "" {
tlsConfig, err = getTLSConfig(certFile)
if err != nil {
return fmt.Errorf("Could not load certs: %s", err)
}
tlsEnabled = true
}
var hl net.Listener
if port > 0 {
hl, err = net.Listen("tcp", fmt.Sprintf("%v:%d", address, port))
} else {
hl, err = pickPort(address, portLow, portHigh, tlsEnabled)
}
if err != nil {
return err
}
if tlsConfig != nil {
hl = tls.NewListener(hl, tlsConfig)
}
hl = slowdown.NewSlowListener(hl, dd.UpKbps*1024, dd.DownKbps*1024)
url := formatURL(tlsEnabled, address, hl.Addr().(*net.TCPAddr).Port)
logger.Say("Listening on %s (%s)", url, hl.Addr().String())
server := &http.Server{Addr: hl.Addr().String(), Handler: mux}
callback(url)
if dd.HasLivereload() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
go func() {
for {
<-c
logger.Say("Received signal - reloading")
dd.lrserver.Reload([]string{"*"})
}
}()
}
err = server.Serve(hl)
logger.Shout("Server stopped: %v", err)
return nil
}
示例2: dirList
func dirList(ci inject.CopyInject, logger termlog.Logger, w http.ResponseWriter, name string, f http.File, templates *template.Template) {
w.Header().Set("Cache-Control", "no-store, must-revalidate")
files, err := f.Readdir(0)
if err != nil {
logger.Shout("Error reading directory for listing: %s", err)
return
}
data := dirData{Name: name, Files: files}
err = ci.ServeTemplate(http.StatusOK, w, templates.Lookup("dirlist.html"), data)
if err != nil {
logger.Shout("Failed to generate dir listing: %s", err)
}
}
示例3: WatchPaths
// WatchPaths watches a set of paths, and broadcasts changes through reloader.
func WatchPaths(paths, excludePatterns []string, reloader livereload.Reloader, log termlog.Logger) error {
ch := make(chan []string, 1)
for _, path := range paths {
modchan := make(chan *moddwatch.Mod, 1)
_, err := moddwatch.Watch([]string{path}, batchTime, modchan)
if err != nil {
return err
}
go func() {
for mod := range modchan {
filteredMod, err := mod.Filter([]string{"**/*"}, excludePatterns)
if err != nil {
log.Shout("Error filtering watches: %s", err)
}
if !filteredMod.Empty() {
ch <- filteredMod.All()
}
}
}()
}
go reloader.Watch(ch)
return nil
}
示例4: Watch
// Watch watches an endpoint for changes, if it supports them.
func (r Route) Watch(ch chan []string, excludePatterns []string, log termlog.Logger) error {
switch r.Endpoint.(type) {
case *filesystemEndpoint:
ep := *r.Endpoint.(*filesystemEndpoint)
modchan := make(chan *moddwatch.Mod, 1)
_, err := moddwatch.Watch([]string{ep.Root + "/..."}, batchTime, modchan)
if err != nil {
return err
}
go func() {
for mod := range modchan {
filteredMod, err := mod.Filter([]string{"**/*"}, excludePatterns)
if err != nil {
log.Shout("Error filtering watches: %s", err)
}
if !filteredMod.Empty() {
ch <- filteredMod.All()
}
}
}()
}
return nil
}
示例5: dirList
func (fserver *FileServer) dirList(logger termlog.Logger, w http.ResponseWriter, name string, f http.File) {
w.Header().Set("Cache-Control", "no-store, must-revalidate")
files, err := f.Readdir(0)
if err != nil {
logger.Shout("Error reading directory for listing: %s", err)
return
}
sortedFiles := fileSlice(files)
sort.Sort(sortedFiles)
data := dirData{
Version: fserver.Version,
Name: name,
Files: sortedFiles,
}
err = fserver.Inject.ServeTemplate(
http.StatusOK,
w,
fserver.Templates.Lookup("dirlist.html"),
data,
)
if err != nil {
logger.Shout("Failed to generate dir listing: %s", err)
}
}
示例6: serveFile
// name is '/'-separated, not filepath.Separator.
func (fserver *FileServer) serveFile(
logger termlog.Logger,
w http.ResponseWriter,
r *http.Request,
name string,
redirect bool,
) {
const indexPage = "/index.html"
// redirect .../index.html to .../
// can't use Redirect() because that would make the path absolute,
// which would be a problem running under StripPrefix
if strings.HasSuffix(r.URL.Path, indexPage) {
logger.SayAs(
"debug", "debug fileserver: redirecting %s -> ./", indexPage,
)
localRedirect(w, r, "./")
return
}
f, err := fserver.Root.Open(name)
if err != nil {
logger.WarnAs("debug", "debug fileserver: %s", err)
if err := fserver.notFound(logger, w, r, name, nil); err != nil {
logger.Shout("Internal error: %s", err)
}
return
}
defer func() { _ = f.Close() }()
d, err1 := f.Stat()
if err1 != nil {
logger.WarnAs("debug", "debug fileserver: %s", err)
if err := fserver.notFound(logger, w, r, name, nil); err != nil {
logger.Shout("Internal error: %s", err)
}
return
}
if redirect {
// redirect to canonical path: / at end of directory url
url := r.URL.Path
if !strings.HasPrefix(url, "/") {
url = "/" + url
}
if d.IsDir() {
if url[len(url)-1] != '/' {
localRedirect(w, r, path.Base(url)+"/")
return
}
} else if url[len(url)-1] == '/' {
localRedirect(w, r, "../"+path.Base(url))
return
}
}
// use contents of index.html for directory, if present
if d.IsDir() {
index := name + indexPage
ff, err := fserver.Root.Open(index)
if err == nil {
defer func() { _ = ff.Close() }()
dd, err := ff.Stat()
if err == nil {
name = index
d = dd
f = ff
}
}
}
// Still a directory? (we didn't find an index.html file)
if d.IsDir() {
if err := fserver.notFound(logger, w, r, name, &f); err != nil {
logger.Shout("Internal error: %s", err)
}
return
}
// serverContent will check modification time
sizeFunc := func() (int64, error) { return d.Size(), nil }
err = serveContent(fserver.Inject, w, r, d.Name(), d.ModTime(), sizeFunc, f)
if err != nil {
logger.Warn("Error serving file: %s", err)
}
}
示例7: notFound
func (fserver *FileServer) notFound(
logger termlog.Logger,
w http.ResponseWriter,
r *http.Request,
name string,
dir *http.File,
) (err error) {
sm := http.NewServeMux()
seen := make(map[string]bool)
for _, nfr := range fserver.NotFoundRoutes {
seen[nfr.MuxMatch()] = true
sm.HandleFunc(
nfr.MuxMatch(),
func(nfr routespec.RouteSpec) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if matchTypes(nfr.Value, r.URL.Path) {
for _, pth := range notFoundSearchPaths(name, nfr.Value) {
next, err := fserver.serveNotFoundFile(w, r, pth)
if err != nil {
logger.Shout("Unable to serve not-found override: %s", err)
}
if !next {
return
}
}
}
err = fserver.serve404(w)
if err != nil {
logger.Shout("Internal error: %s", err)
}
}
}(nfr),
)
}
if _, exists := seen["/"]; !exists {
sm.HandleFunc(
"/",
func(response http.ResponseWriter, request *http.Request) {
if dir != nil {
d, err := (*dir).Stat()
if err != nil {
logger.Shout("Internal error: %s", err)
return
}
if checkLastModified(response, request, d.ModTime()) {
return
}
fserver.dirList(logger, response, name, *dir)
return
}
err = fserver.serve404(w)
if err != nil {
logger.Shout("Internal error: %s", err)
}
},
)
}
handle, _ := sm.Handler(r)
handle.ServeHTTP(w, r)
return err
}
示例8: testpatt
func testpatt(l termlog.Logger) {
l.Say("Log")
l.Notice("Notice!")
l.Warn("Warn!")
l.Shout("Error!")
}