forked from sbotman/go-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
33 lines (27 loc) · 905 Bytes
/
service.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
// All material is licensed under the GNU Free Documentation License
// Package service maintains the logic for the web service.
package service
import (
"fmt"
"net/http"
)
// init binds the routes and handlers for the web service.
func init() {
// Setup a route for our static files.
//
// Because our static directory is set as the root of the FileSystem,
// we need to strip off the /static/ prefix from the request path
// before searching the FileSystem for the given file.
fs := http.FileServer(http.Dir("static"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
// Setup a route for our search.
http.HandleFunc("/search", index)
}
// Run binds the service to a port and starts listening
// for requests.
func Run() {
fmt.Println("http://localhost:9999/search")
fmt.Println("Listening...")
// Listen for our HTTP requests.
http.ListenAndServe("localhost:9999", nil)
}