https://github.com/away0x/flash
Easy flash notifications
https://github.com/away0x/flash
flash go http
Last synced: 9 months ago
JSON representation
Easy flash notifications
- Host: GitHub
- URL: https://github.com/away0x/flash
- Owner: Away0x
- Created: 2019-06-26T05:13:34.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-26T06:06:11.000Z (almost 7 years ago)
- Last Synced: 2025-06-23T00:46:39.220Z (10 months ago)
- Topics: flash, go, http
- Language: Go
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flash
Easy flash notifications
> go get -u github.com/Away0x/flash
```go
package main
import (
"fmt"
"net/http"
"github.com/Away0x/flash"
)
func handler(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPost {
flash.NewFlash("flash", r).
Set(map[string][]string{
"error": {"flash data"},
}).
Save(w)
w.Header().Set("Location", "/")
w.WriteHeader(http.StatusFound)
} else {
val := ""
data := flash.NewFlash("flash", r).Read(w)
if data["error"] != nil && data["error"][0] != "" {
val = data["error"][0]
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprintf(w, `
Submit
Refresh
`+"
"+val+"
")
}
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8000", nil)
}
```