-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
52 lines (41 loc) · 1.38 KB
/
server.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
package main
import (
"fmt"
"log"
"net/http"
"github.com/GiovaniGitHub/cep-weather/configs"
_ "github.com/GiovaniGitHub/cep-weather/docs"
"github.com/GiovaniGitHub/cep-weather/infra/webserver/handlers"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
httpSwagger "github.com/swaggo/http-swagger"
)
// @title Desafio 2.0 - cep-weather
// @version 1.0
// @description Fullcycle Pós Go Expert Go Expert
// @termsOfService http://swagger.io/terms/
// @contact.name Giovani Angelo
// @contact.email giovani.angelo@gmail.com
// @host localhost:8080
// @BasePath /
// @in header
// @name Authorization
func main() {
configs, err := configs.LoadConfig(".")
if err != nil {
log.Fatalf("Erro ao carregar configurações: %v", err)
}
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Route("/cep", func(r chi.Router) {
r.Get("/{cep}", handlers.GetTemperature)
})
// Inicia o servidor
apiURL := configs.URL_BASE + ":" + configs.WebServerPort + "/cep"
log.Printf("API está disponível em: %s", apiURL)
if configs.ENVIRONMENT == "development" {
r.Get("/docs/*", httpSwagger.Handler(httpSwagger.URL(configs.URL_BASE+":"+configs.WebServerPort+"/docs/doc.json")))
log.Printf("API Swagger está disponível em: %s", configs.URL_BASE+":"+configs.WebServerPort+"/docs/index.html")
}
http.ListenAndServe(fmt.Sprintf(":%s", configs.WebServerPort), r)
}