diff --git a/router/go.mod b/router/go.mod new file mode 100644 index 0000000..ec025cf --- /dev/null +++ b/router/go.mod @@ -0,0 +1,5 @@ +module example.com/backend + +go 1.19 + +require github.com/gorilla/mux v1.8.0 // indirect diff --git a/router/go.sum b/router/go.sum new file mode 100644 index 0000000..5350288 --- /dev/null +++ b/router/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= diff --git a/router/router.go b/router/router.go new file mode 100644 index 0000000..fa09fb3 --- /dev/null +++ b/router/router.go @@ -0,0 +1,37 @@ +package router + +import ( + "fmt" + "log" + "net/http" + + "github.com/gorilla/mux" +) + +type App struct { + Myrouterobj *mux.Router + Port string +} + +func (a *App) Initialize() { + + a.Myrouterobj = mux.NewRouter() + +} + +func (a *App) Run() { + a.Myrouterobj.HandleFunc("/", getRequest).Methods("GET") + a.Myrouterobj.HandleFunc("/", postRequest).Methods("POST") + http.Handle("/", a.Myrouterobj) + log.Fatal(http.ListenAndServe(a.Port, nil)) + fmt.Println("Server started on the port ", a.Port) + +} + +func getRequest(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "This is a GET") +} + +func postRequest(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "This is a POST") +} diff --git a/run/go.mod b/run/go.mod new file mode 100644 index 0000000..4db94a5 --- /dev/null +++ b/run/go.mod @@ -0,0 +1,9 @@ +module example.com/run + +go 1.19 + +replace example.com/backend => ../router + +require example.com/backend v0.0.0-00010101000000-000000000000 + +require github.com/gorilla/mux v1.8.0 // indirect diff --git a/run/go.sum b/run/go.sum new file mode 100644 index 0000000..5350288 --- /dev/null +++ b/run/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= diff --git a/run/run.go b/run/run.go new file mode 100644 index 0000000..7ca70bd --- /dev/null +++ b/run/run.go @@ -0,0 +1,13 @@ +package main + +import ( + "example.com/backend" +) + +func main() { + // check if its because of capital letters + myrouterstructobj := backend.App{} + myrouterstructobj.Port = ":8080" + myrouterstructobj.Initialize() + myrouterstructobj.Run() +}