-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (32 loc) · 788 Bytes
/
Copy pathmain.go
File metadata and controls
45 lines (32 loc) · 788 Bytes
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
42
43
44
45
package main
import (
"context"
"fmt"
"log"
"net/http"
"go.mongodb.org/mongo-driver/mongo"
)
const HomeEndpoint = "/"
const UsersEndpoint = "/users"
const PostsEndpoint = "/posts"
var (
DB *mongo.Database
MongoContext context.Context
)
func main() {
client, MongoContext, cancel, err := connect("mongodb://localhost:27017")
if err != nil {
panic(err)
}
defer close(client, MongoContext, cancel)
ping(client, MongoContext)
DB = client.Database("insta-api-test")
handleRequests()
}
func handleRequests() {
http.HandleFunc(HomeEndpoint, HomeHandler)
http.HandleFunc(UsersEndpoint, UsersHandler)
http.HandleFunc(PostsEndpoint, PostsHandler)
fmt.Println("Starting instaapi server at 0.0.0.0:9090 ...")
log.Fatal(http.ListenAndServe(":9090", nil))
}