homogenize tooling

This commit is contained in:
Cadey Ratio 2017-04-29 12:53:08 -07:00
parent 7a3757933d
commit 4f37100b71
6 changed files with 59 additions and 5 deletions

1
cmd/route-httpagent/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
route-httpagent

1
cmd/route/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
route

9
cmd/route/gopreload.go Normal file
View File

@ -0,0 +1,9 @@
// gopreload.go
package main
/*
This file is separate to make it very easy to both add into an application, but
also very easy to remove.
*/
import _ "github.com/Xe/gopreload"

13
cmd/route/gops.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"log"
"github.com/google/gops/agent"
)
func init() {
if err := agent.Listen(nil); err != nil {
log.Fatal(err)
}
}

View File

@ -5,10 +5,14 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"runtime"
"go.uber.org/atomic"
"git.xeserv.us/xena/route/database"
"git.xeserv.us/xena/route/lib/routecrypto"
proto "git.xeserv.us/xena/route/proto"
@ -16,6 +20,7 @@ import (
"github.com/Xe/uuid"
jwtcreds "github.com/Xe/x/tools/svc/credentials/jwt"
"github.com/dickeyxxx/netrc"
"github.com/kr/pretty"
"github.com/olekukonko/tablewriter"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
@ -61,6 +66,9 @@ var (
routesRm = routes.Command("rm", "remove a route")
routesRmID = routesRm.Flag("id", "route ID to remove").Required().String()
testServer = app.Command("test-server", "spawn a simple HTTP test server on a TCP address")
testServerAddr = testServer.Flag("addr", "TCP address").Default(":9090").String()
token = app.Command("token", "token management")
tokenCreate = token.Command("create", "create a new token")
@ -81,13 +89,29 @@ var (
tokenRm = token.Command("rm", "remove a token")
tokenRmHard = tokenRm.Flag("hard", "hard-delete the token instead of deactivating it").Default("false").Bool()
tokenRmID = tokenRm.Flag("id", "token id").Required().String()
// testServer = app.Command("test-server", "spawn a simple HTTP test server on a TCP address")
// testServerAddr = testServer.Flag("addr", "TCP address").Default(":9090").String()
// connect = app.Command("connect", "connect to the backend server and relay client HTTP traffic")
)
var (
hits *atomic.Int64
)
func init() {
hits = atomic.NewInt64(0)
}
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Route is go!")
fmt.Fprintf(w, "%s\n", pretty.Sprintf("%s", r.Header))
hn, _ := os.Hostname()
fmt.Fprintf(w, "Served by %s running %s\n", hn, runtime.GOOS)
fmt.Fprintf(w, "Hit count: %d", hits.Inc())
ip := r.Header.Get("X-Remote-Ip")
if ip != "" {
log.Printf("Hit from %s: %s", ip, r.RequestURI)
}
}
func main() {
cmdline := kingpin.MustParse(app.Parse(os.Args[1:]))
@ -98,6 +122,11 @@ func main() {
_ = n
switch cmdline {
case "test-server":
http.HandleFunc("/", handle)
ln.Fatal(ln.F{"err": http.ListenAndServe(*testServerAddr, nil), "action": "test_server"})
case "generate-key":
key, err := routecrypto.GenerateKey()
if err != nil {

1
cmd/routed/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
routed