Ejemplo n.º 1
0
func main() {
	listenAddr, baseDir, rawPatch := processArgs()

	nav, err := navpatch.NewNavigator(baseDir, rawPatch)
	if err != nil {
		internal.ErrorExit(err)
	}

	listener, err := net.Listen("tcp", listenAddr)
	if err != nil {
		internal.ErrorExit("starting server:", err)
	}

	fmt.Println("Serving at " + listener.Addr().String())
	log.Fatal(http.Serve(listener, nav))
}
Ejemplo n.º 2
0
func processArgs() (string, string, []byte) {
	args := os.Args
	if len(args) < 2 || len(args) > 4 {
		badArgs()
	}

	if args[1] == "-h" {
		usage()
		os.Exit(0)
	} else if len(args) < 3 {
		badArgs()
	}

	var rawPatch []byte
	var err error
	if len(args) == 3 {
		rawPatch, err = ioutil.ReadAll(os.Stdin)
	} else {
		rawPatch, err = ioutil.ReadFile(args[3])
		if err != nil {
			resp, getErr := http.Get(args[3])
			if getErr == nil {
				rawPatch, err = ioutil.ReadAll(resp.Body)
			}
		}
	}
	if err != nil {
		internal.ErrorExit(err)
	}

	return args[1], args[2], rawPatch
}
Ejemplo n.º 3
0
func main() {
	flag.Parse()

	whitelistStr := strings.Split(*whitelistFlag, "|")
	whitelist := make([]*regexp.Regexp, 0, len(whitelistStr))
	for _, s := range whitelistStr {
		rgx, err := regexp.Compile(s)
		if err != nil {
			internal.ErrorExit("compiling whitelist regexps:", err)
		}
		whitelist = append(whitelist, rgx)
	}

	h := navpatchserve.NewHandler(*cloneDir, "git_command_unix", *sessionsLimit, whitelist, *timePerSession)

	listener, err := net.Listen("tcp", *listenAddr)
	if err != nil {
		internal.ErrorExit("starting server:", err)
	}

	fmt.Println("Serving at " + listener.Addr().String())
	log.Fatal(http.Serve(listener, h))
}