func init() { ktpl = MustParse(bench_kt) ktpl.EscapeFunc = nil gtpl = template.MustParse(bench_tpl, nil) for ii := 0; ii < len(bctx.Arr); ii++ { bctx.Arr[ii] = map[string]interface{}{ "I": ii, "A": ii * 2, "B": `aąbcćdeęfghijklłmnńoóprsśtuvwxżż AĄBCĆDEĘFGHIJKLŁMNŃOÓPRSŚTUVWXYŻŹ`, } } }
func main() { ktpl = kasia.MustParse(bench_kt) ktpl.EscapeFunc = nil gtpl = template.MustParse(bench_tpl, nil) for ii := 0; ii < len(bctx.Arr); ii++ { bctx.Arr[ii] = map[string]interface{}{ "I": ii, "A": ii * 2, "B": `aąbcćdeęfghijklłmnńoóprsśtuvwxżż AĄBCĆDEĘFGHIJKLŁMNŃOÓPRSŚTUVWXYŻŹ`, } } fmt.Println("Kasia:") fmt.Println(testing.Benchmark(kbench)) fmt.Println("Go template:") fmt.Println(testing.Benchmark(tbench)) }
{.or} ### Nagios Host Check Result ### {.end} # Time: Wed Jun 1 16:58:28 2011 host_name={Hostname} {.section ServiceName} service_description={@} {.end} check_type={CheckPassive} check_options=0 scheduled_check=1 reschedule_check=1 latency=0.210000 start_time={StartTimestamp} finish_time={EndTimestamp} early_timeout=0 exited_ok=1 return_code={Status} output={CheckOutput} ` var fmap = template.FormatterMap{ "escstr": escapedStringFormatter, } func escapedStringFormatter(w io.Writer, format string, value ...interface{}) { template.StringFormatter(w, format, strings.Trim(strconv.Quote(value[0].(string)), "\"")) } var tActiveCheck = template.MustParse(activeCheck, nil)
"http" "io" "json" "log" "net" "old/template" "runtime" "strings" "websocket" ) var Store *store.Store var ClusterName string var ( mainTpl = template.MustParse(main_html, nil) statsTpl = template.MustParse(stats_html, nil) ) type info struct { Name string Path string } type stringHandler struct { contentType string body string } func (sh stringHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("content-type", sh.contentType)
import ( "flag" "http" "io" "log" "old/template" // New template package coming soon... "url" ) var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18 var fmap = template.FormatterMap{ "html": template.HTMLFormatter, "url+html": UrlHtmlFormatter, } var templ = template.MustParse(templateStr, fmap) func main() { flag.Parse() http.Handle("/", http.HandlerFunc(QR)) err := http.ListenAndServe(*addr, nil) if err != nil { log.Fatal("ListenAndServe:", err) } } func QR(w http.ResponseWriter, req *http.Request) { templ.Execute(w, req.FormValue("s")) } func UrlHtmlFormatter(w io.Writer, fmt string, v ...interface{}) {
func (self *Summary) String() string { t := template.MustParse(OutPutTemplate, CustomFormatter) sw := new(StringWritter) t.Execute(sw, self) return sw.s }
flagPassive = flag.Bool("passive", true, "submit as passive check") flagCmdlist = flag.Bool("cmdlist", false, "arg is a file containing commands") flagAddr = flag.String("addr", ":8323", "http service address") flagEndpoint = flag.String("endpoint", "/ncd/", "http service endpoint") flagUseSSL = flag.Bool("ssl", false, "use ssl") flagSSLCert = flag.String("cert", "cert.pem", "ssl cert file") flagSSLKey = flag.String("key", "key.pem", "ssl key file") flagSpoolDir = flag.String("spooldir", "/var/nagios/spool/checkresults", "nagios spool directory") flagSyslog = flag.Bool("syslog", true, "log to syslog- if false, log to stdout") flagUsername = flag.String("username", "npd", "basic auth username") flagPassword = flag.String("password", "npd", "basic auth password") logger = syslog.NewLogger(syslog.LOG_INFO, log.Flags()) ) var templ = template.MustParse(templateStr, nil) func root(w http.ResponseWriter, r *http.Request) { // check header if *flagPassword != "" && *flagUsername != "" { auth, ok := r.Header["Authorization"] if ok && strings.HasPrefix(auth[0], "Basic ") { str := strings.TrimLeft(auth[0], "Basic ") decode, err := base64.StdEncoding.DecodeString(str) if err != nil { log.Print("cannot decode auth string: ", err) return } user, pass, err := url.UnescapeUserinfo(string(decode)) if err != nil { log.Print("auth: couldn't decode user/pass: ", err)