Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ApiFuncs = map[string]ApiFunc{ "generate": Generate, "parse": Parse, }
View Source
var GetHttpHandle = func() http.Handler { root, _ := fs.Sub(Webfs, "dist") fileServer := http.FileServer(http.FS(root)) indexHtml, _ := Webfs.ReadFile("dist/index.html") indexHtmlStr := string(indexHtml) variables := map[string]string{ "ROOTPATH": flags.Rootpath, "PREFIX": flags.Prefix, "SITENAME": flags.Sitename, "ENV": "production", "VERSION": version.Version, } marker := "; //__" endmarker := "__" variableRegex := regexp.MustCompile(`".*?"` + regexp.QuoteMeta(marker) + `([A-Z][_A-Z0-9]*?)` + regexp.QuoteMeta(endmarker)) indexHtmlStr = variableRegex.ReplaceAllStringFunc(indexHtmlStr, func(s string) string { i := strings.Index(s, marker) j := strings.LastIndex(s, endmarker) variable := s[i+len(marker) : j] if value, ok := variables[variable]; ok { return fmt.Sprintf(`%q%s`, value, s[i:]) } return s }) indexHtml = []byte(indexHtmlStr) handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if flags.Cors { w.Header().Set("Access-Control-Allow-Origin", "*") } path := strings.TrimPrefix(r.URL.Path, "/") f, err := root.Open(path) if err == nil { defer f.Close() } if path == "api" { apiHandler(w, r) return } if path == "" || os.IsNotExist(err) { w.Write(indexHtml) return } fileServer.ServeHTTP(w, r) }) if flags.Pass != "" { authenticator := auth.NewAuthenticator("website", false) handler = authenticator.Wrap(handler, flags.User, flags.Pass, flags.BasicAuth) } return handler }
View Source
var Webfs embed.FS
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.