func main() { var err error connPoolConfig := pgx.ConnPoolConfig{ ConnConfig: pgx.ConnConfig{ Host: "127.0.0.1", User: "******", Password: "******", Database: "url_shortener", Logger: log.New("module", "pgx"), }, MaxConnections: 5, AfterConnect: afterConnect, } pool, err = pgx.NewConnPool(connPoolConfig) if err != nil { log.Crit("Unable to create connection pool", "error", err) os.Exit(1) } http.HandleFunc("/", urlHandler) log.Info("Starting URL shortener on localhost:8080") err = http.ListenAndServe("localhost:8080", nil) if err != nil { log.Crit("Unable to start web server", "error", err) os.Exit(1) } }
func buildCmd(c *cli.Context) { exit := func(err error) { if err == nil { os.Exit(0) } else { log.Crit("command failed", "err", err) os.Exit(1) } } opts := &Options{ Version: c.String("version"), SrcPath: c.String("src"), TargetPath: c.String("target"), } platforms := c.String("platforms") if platforms == "" { opts.Platforms = defaultPlatforms } else { opts.Platforms = make([]Platform, 0) for _, pString := range strings.Split(platforms, " ") { parts := strings.Split(pString, "_") if len(parts) != 2 { exit(fmt.Errorf("Invalid platform string: %v", pString)) } opts.Platforms = append(opts.Platforms, Platform{parts[0], parts[1]}) } } exit(Build(opts)) }