2023-10-07 17:12:47 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-08 14:25:57 +01:00
|
|
|
"bufio"
|
2023-10-07 17:12:47 +01:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/ray1729/puzzle-solver/anagram"
|
2023-10-08 14:25:57 +01:00
|
|
|
"github.com/ray1729/puzzle-solver/match"
|
2023-10-07 17:12:47 +01:00
|
|
|
"github.com/ray1729/puzzle-solver/server"
|
|
|
|
)
|
|
|
|
|
2023-10-08 14:25:57 +01:00
|
|
|
var matchDB match.DB
|
2023-10-07 17:12:47 +01:00
|
|
|
var anagramDB anagram.DB
|
|
|
|
|
|
|
|
func init() {
|
2023-10-08 14:25:57 +01:00
|
|
|
f, err := os.Open("wordlist.txt")
|
2023-10-07 17:12:47 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error opening word list: %v", err)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
2023-10-08 14:25:57 +01:00
|
|
|
matchDB = match.New()
|
|
|
|
anagramDB = anagram.New()
|
|
|
|
sc := bufio.NewScanner(f)
|
|
|
|
for sc.Scan() {
|
|
|
|
s := sc.Text()
|
|
|
|
matchDB.Add(s)
|
|
|
|
anagramDB.Add(s)
|
2023-10-07 17:12:47 +01:00
|
|
|
}
|
2023-10-08 14:25:57 +01:00
|
|
|
if err := sc.Err(); err != nil {
|
|
|
|
log.Fatalf("Error loading databases: %v", err)
|
2023-10-07 17:12:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2023-10-08 14:25:57 +01:00
|
|
|
s := server.New("./assets", matchDB, anagramDB)
|
2023-10-07 17:12:47 +01:00
|
|
|
address := ":8000"
|
|
|
|
log.Printf("Listening on %s", address)
|
|
|
|
if err := http.ListenAndServe(address, s); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|