github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/cmd/hook_stub_gen/main.go (about) 1 package main // import "github.com/Azareal/Gosora/hook_stub_gen" 2 3 import ( 4 "fmt" 5 "log" 6 "strings" 7 "runtime/debug" 8 9 h "github.com/Azareal/Gosora/cmd/common_hook_gen" 10 ) 11 12 // TODO: Make sure all the errors in this file propagate upwards properly 13 func main() { 14 // Capture panics instead of closing the window at a superhuman speed before the user can read the message on Windows 15 defer func() { 16 if r := recover(); r != nil { 17 fmt.Println(r) 18 debug.PrintStack() 19 } 20 }() 21 22 imports := []string{"net/http"} 23 hookVars := h.HookVars{imports,nil} 24 add := func(name, params, ret, htype string, multiHook, skip bool, defaultRet, pure string) { 25 var params2 string 26 first := true 27 for _, param := range strings.Split(params,",") { 28 if !first { 29 params2 += "," 30 } 31 pspl := strings.Split(strings.ReplaceAll(strings.TrimSpace(param)," "," ")," ") 32 params2 += pspl[0] 33 first = false 34 } 35 hookVars.Hooks = append(hookVars.Hooks, h.Hook{name, params, params2, ret, htype, true, multiHook, skip, defaultRet,pure}) 36 } 37 38 h.AddHooks(add) 39 h.Write(hookVars) 40 log.Println("Successfully generated the hooks") 41 }