-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (34 loc) · 773 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
42
package main
import (
"fmt"
"log"
"net/http"
"os"
"regsan-check/nso"
"github.com/gorilla/mux"
)
// map for product data using nso keys
var productos nso.TablaProductos
func init() {
// initialize productos map
// Read data from spreadsheet using its id
sheetID := "1fM4UC4Y9uxkzJxIKFnW0h_YVAlB5qQ2cQdl4VuxmnnA"
productos = nso.GetDataFromGsheet(sheetID)
}
func main() {
// Serve api
port := os.Getenv("PORT")
if port == "" {
log.Println("$PORT not set, defaulting to 8080")
port = "8080"
}
r := mux.NewRouter()
h := nso.NewHandler(&productos)
r.Queries(
"nso", "[a-zA-z0-9-\\s]+",
"producto", "",
)
r.Handle("/check-nso", h).Methods(http.MethodGet)
fmt.Printf("Serving at port:%s\n", port)
log.Fatal(http.ListenAndServe(":"+port, r))
}