1234567891011121314151617181920212223242526272829303132333435 |
- package main
- import (
- "database/sql"
- "fmt"
- "net/http"
- "encoding/xml"
- _ "github.com/go-sql-driver/mysql"
- )
- type User struct {
- Name string `xml:"name"`
- Email string `xml:"email"`
- ID int `xml:"int"`
- }
- func userRouter(w http.ResponseWriter, r *http.Request) {
- ourUser := User{
- Name: "Bill Smith",
- Email: "bill.smith@example.com",
- ID: 100,
- }
- output, _ := xml.MarshalIndent(&ourUser, "", " ")
- fmt.Fprint(w, string(output))
- }
- var database *sql.DB
- func main() {
- fmt.Println("Starting XML server")
- http.HandleFunc("/user", userRouter)
- http.ListenAndServe(":8080", nil)
- }
|