forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (33 loc) · 969 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
38
39
40
41
// This program provides a sample web service that implements a
// RESTFul CRUD API against a MongoDB database.
package main
import (
"log"
"net/http"
"os"
"os/signal"
"github.com/ardanlabs/gotraining/topics/http/api/routes"
)
// init is called before main. We are using init to customize logging output.
func init() {
log.SetFlags(log.LstdFlags | log.Lmicroseconds | log.Lshortfile)
}
// main is the entry point for the application.
func main() {
log.Println("main : Started")
// Check the environment for a configured port value.
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
// Create this goroutine to run the web server.
go func() {
log.Println("listener : Started : Listening on: http://localhost:" + port)
http.ListenAndServe(":"+port, routes.API())
}()
// Listen for an interrupt signal from the OS.
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
<-sigChan
log.Println("main : Completed")
}