-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
43 lines (36 loc) · 976 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"net/http"
"google.golang.org/appengine"
)
func init() {
http.HandleFunc("/", IndexHandler)
}
func IndexHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
GetIndex(w, r)
case http.MethodPost:
PostIndex(w, r)
default:
NotFound(w, r)
}
}
func GetIndex(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "text/plain")
fmt.Fprint(w, "a plaintext pastebin service")
}
func PostIndex(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusFound)
w.Header().Set("Location", "http:https://cdn.pasteraw.com/")
}
func NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
w.Header().Set("Content-Type", "text/plain")
fmt.Fprintf(w, "%d Not Found", http.StatusNotFound)
}
func main() {
appengine.Main()
}