Skip to content

Commit 5d9e392

Browse files
committed
add recovery handler generator.
1 parent 606ac9b commit 5d9e392

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

cmd/samb-medic/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

cmd/samb-medic/template.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
`

0 commit comments

Comments
 (0)