37 lines
594 B
Go
37 lines
594 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"regexp"
|
|
|
|
"git.1e99.eu/1e99/chitchat/server/storage"
|
|
)
|
|
|
|
func run() error {
|
|
address := ":3000"
|
|
store := storage.NewMemStore()
|
|
|
|
idRegex := regexp.MustCompile(`^[A-Za-z0-9]+$`)
|
|
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/store/{id}", StoreHandler(store, idRegex, 4*1024*1024))
|
|
|
|
log.Printf("Listening on port %s", address)
|
|
err := http.ListenAndServe(address, mux)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to listen: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
err := run()
|
|
if err != nil {
|
|
fmt.Printf("%s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|