File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "flag"
5
+ "fmt"
6
+ "io/ioutil"
7
+ "os"
8
+ )
9
+
10
+ func main () {
11
+
12
+ name := flag .String ("name" , "FooBar" , "Name of recovery function to add." )
13
+ project := flag .String ("project" , "./" , "Path to project" )
14
+
15
+ flag .Parse ()
16
+
17
+ os .Chdir (* project )
18
+
19
+ // set path to where the handler source will be saved
20
+ savePath := "./pkg/api/" + * name + "_recover.go"
21
+
22
+ recoverySource := fmt .Sprintf (recoveryHandlerTemplate , * name , * name )
23
+
24
+ fmt .Println ("Saving file to : " , savePath )
25
+ err := ioutil .WriteFile (savePath , []byte (recoverySource ), 0700 )
26
+
27
+ if err != nil {
28
+ panic (err )
29
+ }
30
+
31
+ fmt .Println ("Add this to your server's recover directive : do " , * name + ";" )
32
+
33
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ var recoveryHandlerTemplate = `package api
4
+
5
+ import (
6
+ "net/http"
7
+ )
8
+
9
+ // %s handles recovery of requests.
10
+ func %s(w http.ResponseWriter, r *http.Request, m string) {
11
+
12
+
13
+ w.Write([]byte("Please implement me."))
14
+
15
+ }
16
+ `
You can’t perform that action at this time.
0 commit comments