Guest User

Untitled

a guest
Nov 4th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. func main() {
  2. router := app.CreateRouter(app.Routes())
  3. log.Fatal(http.ListenAndServe(":8080", router))
  4. }
  5.  
  6. type Config struct {
  7. DB *sql.DB
  8. }
  9.  
  10. func (c *Config) connectToDB() {
  11. connectionString := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", os.Getenv("DB_USERNAME"), os.Getenv("DB_PASSWORD"), os.Getenv("DB_NAME"))
  12. var err error
  13. c.DB, err = sql.Open("postgres", connectionString)
  14. if err != nil {
  15. log.Fatal(err)
  16. }
  17. }
  18.  
  19. func init() {
  20. c := Config{}
  21. c.connectToDB()
  22. }
  23.  
  24. func UserIndex(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
  25. fmt.Fprint(w, "test!n")
  26. }
Add Comment
Please, Sign In to add comment