Ejemplo n.º 1
0
func setupServer(conf *config.Config) (err error) {
	dbConn, err = db.Open(conf.Redis.DSN)

	if err != nil {
		return
	}

	newWordfilter = func(list wordlist.Wordlist) *wordfilter.Wordfilter {
		var replacer wordfilter.Replacer

		switch conf.Filter {
		case types.Any:
			replacer = wordfilter.NewStringReplacer()
		case types.Word:
			replacer = wordfilter.NewSetReplacer()
		default:
			replacer = wordfilter.NewSetReplacer()
		}

		return &wordfilter.Wordfilter{
			List:     list,
			Replacer: replacer,
		}
	}

	filters = newProfanityFilters()

	// HTTP endpoints
	router = mux.NewRouter()
	router.HandleFunc("/v1/profanity/sanitize/", sanitizeHandle).Methods("GET").Name("sanitize")
	router.HandleFunc("/v1/profanity/blacklist/", updateBlacklistHandle).Methods("POST", "PUT").Name("blacklist")
	router.HandleFunc("/v1/profanity/blacklist/remove/", removeBlacklistHandle).Methods("POST", "PUT").Name("blacklist")
	router.HandleFunc("/v1/profanity/blacklist/", getBlacklistHandle).Methods("GET").Name("blacklist")
	router.StrictSlash(false)

	// global middleware
	var middleware []func(http.Handler) http.Handler

	switch log.Severity {
	case log.LevelDebug:
		middleware = append(middleware, handler.LogHandler, handler.DebugHandle, handler.RecoveryHandler)
	default:
		middleware = append(middleware, handler.LogHandler, handler.RecoveryHandler)
	}

	wrapped := handler.Use(router, middleware...)
	http.Handle("/", wrapped)
	return
}
Ejemplo n.º 2
0
func setupServer(storage blobserver.Storage) (err error) {
	router := mux.NewRouter()

	sub := router.PathPrefix("/v1/api/blobserver/blob").Subrouter()
	pat.Post(sub, "/upload/", createUploadHandler(storage))
	pat.Delete(sub, `/remove/{blobRef:[[:alnum:]_\/\.-]+}/`, createRemoveHandler(storage))
	pat.Post(sub, "/remove/", createBatchRemoveHandler(storage))
	pat.Get(sub, `/stat/{blobRef:[[:alnum:]_\/\.-]+}/`, createStatHandler(storage))
	pat.Head(sub, `/stat/{blobRef:[[:alnum:]_\/\.-]+}/`, createStatHandler(storage))
	pat.Get(sub, "/stat/", createBatchStatHandler(storage))

	sub = router.PathPrefix("/v1/api/blobserver").Subrouter()
	pat.Get(sub, "/config/", createConfigHandler(storage))

	router.StrictSlash(false)

	// global middleware
	wrapped := handler.Use(router, handler.LogHandler, handler.RecoveryHandler)
	http.Handle("/", wrapped)
	return nil
}