Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions router/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module example.com/backend

go 1.19

require github.com/gorilla/mux v1.8.0 // indirect
2 changes: 2 additions & 0 deletions router/go.sum
Original file line number Diff line number Diff line change
@@ -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=
37 changes: 37 additions & 0 deletions router/router.go
Original file line number Diff line number Diff line change
@@ -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")
}
9 changes: 9 additions & 0 deletions run/go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions run/go.sum
Original file line number Diff line number Diff line change
@@ -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=
13 changes: 13 additions & 0 deletions run/run.go
Original file line number Diff line number Diff line change
@@ -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()
}