1
0
mirror of synced 2024-11-25 22:36:03 +03:00

Remove dependency on paked/configure from basic example

This commit is contained in:
Samuel El-Borai 2018-03-18 20:54:43 +01:00
parent e011679fe8
commit be1779c3c5
2 changed files with 20 additions and 20 deletions

View File

@ -1,6 +0,0 @@
{
"verify-token": "",
"should-verify": false,
"page-token": "",
"app-secret": ""
}

View File

@ -1,29 +1,35 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"log"
"net/http" "net/http"
"os"
"time" "time"
"github.com/paked/configure"
"github.com/paked/messenger" "github.com/paked/messenger"
) )
var ( var (
conf = configure.New() verifyToken = flag.String("verify-token", "mad-skrilla", "The token used to verify facebook (required)")
verifyToken = conf.String("verify-token", "mad-skrilla", "The token used to verify facebook") verify = flag.Bool("should-verify", false, "Whether or not the app should verify itself")
verify = conf.Bool("should-verify", false, "Whether or not the app should verify itself") pageToken = flag.String("page-token", "not skrilla", "The token that is used to verify the page on facebook")
pageToken = conf.String("page-token", "not skrilla", "The token that is used to verify the page on facebook") appSecret = flag.String("app-secret", "", "The app secret from the facebook developer portal (required)")
appSecret = conf.String("app-secret", "", "The app secret from the facebook developer portal") host = flag.String("host", "localhost", "The host used to serve the messenger bot")
port = conf.Int("port", 8080, "The port used to serve the messenger bot") port = flag.Int("port", 8080, "The port used to serve the messenger bot")
) )
func main() { func main() {
conf.Use(configure.NewFlag()) flag.Parse()
conf.Use(configure.NewEnvironment())
conf.Use(configure.NewJSONFromFile("config.json"))
conf.Parse() if *verifyToken == "" || *appSecret == "" || *pageToken == "" {
fmt.Println("missing arguments")
fmt.Println()
flag.Usage()
os.Exit(-1)
}
// Create a new messenger client // Create a new messenger client
client := messenger.New(messenger.Options{ client := messenger.New(messenger.Options{
@ -55,7 +61,7 @@ func main() {
fmt.Println("Read at:", m.Watermark().Format(time.UnixDate)) fmt.Println("Read at:", m.Watermark().Format(time.UnixDate))
}) })
fmt.Printf("Serving messenger bot on localhost:%d\n", *port) addr := fmt.Sprintf("%s:%d", *host, *port)
log.Println("Serving messenger bot on", addr)
http.ListenAndServe(fmt.Sprintf("localhost:%d", *port), client.Handler()) log.Fatal(http.ListenAndServe(addr, client.Handler()))
} }