42 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
package api
 | 
						|
 | 
						|
import (
 | 
						|
	"net/http"
 | 
						|
 | 
						|
	"git.coopgo.io/coopgo-apps/parcoursmob/core/application"
 | 
						|
	"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/cache"
 | 
						|
	"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/geo"
 | 
						|
	"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
 | 
						|
	cacheStorage "git.coopgo.io/coopgo-apps/parcoursmob/core/utils/storage"
 | 
						|
	"github.com/spf13/viper"
 | 
						|
)
 | 
						|
 | 
						|
type Handler struct {
 | 
						|
	config            *viper.Viper
 | 
						|
	idp               *identification.IdentificationProvider
 | 
						|
	applicationHandler *application.ApplicationHandler
 | 
						|
	cacheService      *cache.CacheService
 | 
						|
	geoService        *geo.GeoService
 | 
						|
}
 | 
						|
 | 
						|
func NewHandler(cfg *viper.Viper, idp *identification.IdentificationProvider, appHandler *application.ApplicationHandler, cacheHandler cacheStorage.CacheHandler) *Handler {
 | 
						|
	cacheService := cache.NewCacheService(cacheHandler)
 | 
						|
 | 
						|
	// Get geocoding configuration
 | 
						|
	geoType := cfg.GetString("geo.type")
 | 
						|
	baseURL := cfg.GetString("geo." + geoType + ".url")
 | 
						|
	autocompleteEndpoint := cfg.GetString("geo." + geoType + ".autocomplete")
 | 
						|
	geoService := geo.NewGeoService(geoType, baseURL, autocompleteEndpoint)
 | 
						|
 | 
						|
	return &Handler{
 | 
						|
		config:            cfg,
 | 
						|
		idp:               idp,
 | 
						|
		applicationHandler: appHandler,
 | 
						|
		cacheService:      cacheService,
 | 
						|
		geoService:        geoService,
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
func (h *Handler) NotFound(w http.ResponseWriter, r *http.Request) {
 | 
						|
	w.WriteHeader(http.StatusNotFound)
 | 
						|
} |