Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: first architecture proposition #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Empty file added Makefile
Empty file.
Empty file added configs/.gitkeep
Empty file.
Empty file added docs/.gitkeep
Empty file.
Empty file added docs/docs.md
Empty file.
Empty file added examples/.gitkeep
Empty file.
Empty file added examples/hello-world/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/HETIC-MT-P2021/framework_project

go 1.15

require github.com/gorilla/mux v1.8.0
2 changes: 2 additions & 0 deletions 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=
Empty file added internal/.gitkeep
Empty file.
52 changes: 52 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"context"
"github.com/gorilla/mux" // need to use dep for package management
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)

func TestEndpoint(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("Test is what we usually do"))
}

func main() {
router := mux.NewRouter()
router.HandleFunc("/test", TestEndpoint).Methods("GET")

srv := &http.Server{
Addr: ":8080",
Handler: router,
}

done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("listen: %s\n", err)
}
}()
log.Print("Server Started")

<-done
log.Print("Server Stopped")

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer func() {
// extra handling here
cancel()
}()

if err := srv.Shutdown(ctx); err != nil {
log.Fatalf("Server Shutdown Failed:%+v", err)
}
log.Print("Server Exited Properly")

}
Empty file added pkg/.gitkeep
Empty file.
Empty file added test/.gitkeep
Empty file.
Empty file added website/.gitkeep
Empty file.