Golang Web框架Buffalo 简单使用

官方文档 https://gobuffalo.io 安装 安装要求 Before installing make sure you have the required dependencies installed: A working Go environment Go version v1.16.0. Frontend Requirements# The following requirements are optional. You don’t need them if you want to build an API or if you prefer to build your app in an old-fashioned way. node version 8 or greater either yarn or npm for the asset pipeline built upon webpack. Database Specific Requirements# Again, if you don’t need a database, you won’t need these....

January 29, 2023 · 1 min · czyt

golang webserver with genergic base64 /favicon.ico

package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/favicon.ico", favicon) http.HandleFunc("/", hello) fmt.Printf("listening on http://localhost:8000/\n") http.ListenAndServe("localhost:8000", nil) } func favicon(w http.ResponseWriter, r *http.Request) { fmt.Printf("%s\n", r.RequestURI) w.Header().Set("Content-Type", "image/x-icon") w.Header().Set("Cache-Control", "public, max-age=7776000") fmt.Fprintln(w, "data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=\n") } func hello(w http.ResponseWriter, r *http.Request) { fmt.Printf("%s\n", r.RequestURI) fmt.Fprintln(w, "Hello, World!") }

February 23, 2022 · 1 min · czyt