package main import ( "database/sql" "fmt" "net/http" "encoding/csv" _ "github.com/go-sql-driver/mysql" "strconv" ) // Tags are not actually used at this point. Probably never. type User struct { Name string `csv:"name"` Email string `csv:"email"` ID int `csv:"int"` } func userRouter(w http.ResponseWriter, r *http.Request) { ourUser := User{ Name: "Bill Smith", Email: "bill,smith@example.com", ID: 100, } row := []string{ ourUser.Name, ourUser.Email, strconv.Itoa(ourUser.ID), } csvWriter := csv.NewWriter(w) csvWriter.Write(row) csvWriter.Flush() } var database *sql.DB func main() { fmt.Println("Starting CSV server") http.HandleFunc("/user", userRouter) http.ListenAndServe(":8080", nil) }