mirror of
https://github.com/SourceFellows/gobuch.git
synced 2024-10-22 22:05:35 +00:00
30 lines
598 B
Go
30 lines
598 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
var jsonDoc1 = []byte("{\"Name\":\"")
|
||
|
var jsonDoc2 = []byte("\"}")
|
||
|
|
||
|
func myHandler(writer http.ResponseWriter, req *http.Request) {
|
||
|
path := req.URL.Path
|
||
|
|
||
|
if len(path) < 6 || path[:6] != "/json/" {
|
||
|
writer.WriteHeader(http.StatusNotImplemented)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
writer.Header().Add("Content-Type", "application/json")
|
||
|
bites := make([]byte, 20)
|
||
|
bites = append(bites, jsonDoc1...)
|
||
|
bites = append(bites, path[6:]...)
|
||
|
bites = append(bites, jsonDoc2...)
|
||
|
writer.Write(bites)
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
http.HandleFunc("/", myHandler)
|
||
|
http.ListenAndServe(":8080", nil)
|
||
|
}
|