-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (47 loc) · 1.53 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//go:generate swagger generate spec
// Package main Loggenerator.
//
// the purpose of this application is to provide an interface to Generate different Log
//
// Terms Of Service:
//
// there are no TOS at this moment, use at your own risk we take no responsibility
//
// Schemes: http
// Host: localhost
// BasePath: /
// Version: 0.0.1
// License: MIT http://opensource.org/licenses/MIT
// Contact: Julien SENON <julien.senon@gmail.com>
package main
import (
"log"
"net/http"
"github.com/jsenon/loggenerator/logrusgen"
"github.com/jsenon/loggenerator/web"
"github.com/jsenon/loggenerator/zapgen"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
// Remove CORS Header check to allow swagger and application on same host and port
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type"})
// To be changed
originsOk := handlers.AllowedOrigins([]string{"*"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS", "PATCH"})
// Web Part
// r.HandleFunc("/index", web.Index)
r.HandleFunc("/healthz", web.Healthz)
// Swagger
// r.HandleFunc("/api", web.ApiHelp)
// API Part
r.HandleFunc("/log/logrus", logrusgen.Generate).Methods("POST")
r.HandleFunc("/log/zapsugar", zapgen.Generatesugar).Methods("POST")
r.HandleFunc("/log/zaplogger", zapgen.Generatelogger).Methods("POST")
// Static dir
err := http.ListenAndServe(":9030", handlers.CORS(originsOk, headersOk, methodsOk)(r))
if err != nil {
log.Fatal(err)
}
}