-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (33 loc) · 885 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
package main
import (
"fmt"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"log"
"net/http"
"github.com/numine777/OffByOne/core"
"reflect"
)
func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to Off By One!")
fmt.Println("Endpoint Hit: homePage")
}
func handleRequests(db *gorm.DB) {
master := core.GetApi(db)
methods := reflect.TypeOf(master)
for i := 0; i < methods.NumMethod(); i++ {
method := reflect.ValueOf(master).Method(i)
methodName := methods.Method(i).Name
http.HandleFunc(fmt.Sprintf("/api/%v", methodName), superSmartPost(&method))
}
http.HandleFunc(fmt.Sprintf("/"), homePage)
fmt.Println("Successfully setup running on port 6969!")
log.Fatal(http.ListenAndServe(":6969", nil))
}
func main() {
db, err := gorm.Open(sqlite.Open("testdb.sqlite3"), &gorm.Config{})
if err != nil {
panic(err)
}
handleRequests(db)
}