-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (33 loc) · 937 Bytes
/
main.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
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
func main() {
exit := make(chan os.Signal, 1)
signal.Notify(exit, os.Interrupt, syscall.SIGTERM)
// Serve the "static" folder at the base URL ("/")
http.Handle("/", http.FileServer(http.Dir("static")))
http.Handle("static/project06.css", http.FileServer(http.Dir("./")))
// Start the HTTP server in a goroutine
go func() {
fmt.Println("Starting HTTP server on :8080")
if err := http.ListenAndServe(":8080", nil); err != nil {
fmt.Println(err)
}
}()
url := "https://openai.com/robots.txt"
StopWords = createSWmap("stopwords-en.json")
ebook := Index{}
ebook.initializeDatabase(url)
// ebook.createRobotMap(url)
fmt.Println("Finished crawling all urls.")
// when the server reaches the /search url, use the function search
http.HandleFunc("/search", ebook.searchHandlerDatabase)
<-exit
log.Println("Shutting down server.")
}