FAQ
package main

import (
        "net/http"
        "html/template"

)

type Context struct {
        FirstName string
        Message string

}

func hello(w http.ResponseWriter, req *http.Request) {
        w.Header().Add("Content Type", "text/html")
        tmpl, err := template.New("anyName").Parse("index.html")
        if err == nil {
               context := Context{"Coolio", "more Go, Please"}
               tmpl.Execute(w, context)
        }
}


func myHanderFunc(w http.ResponseWriter, r *http.Request) {
        template.Must(template.ParseFiles("index.html")).Execute(w, hello)
}

func main() {
        http.HandleFunc("/", myHanderFunc)
        http.Handle("/images/", http.StripPrefix("/images/",
http.FileServer(http.Dir("images"))))
        http.ListenAndServe(":9090", nil)
}


How do i update content on my site with Go?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Volker Dobler at Jan 23, 2016 at 10:44 am
    Maybe you could provide more information, especially about
    what you try to achieve, what you tried and why it failed.

    V.

    Am Samstag, 23. Januar 2016 06:43:33 UTC+1 schrieb Gunnar Helgason:
    package main

    import (
    "net/http"
    "html/template"

    )

    type Context struct {
    FirstName string
    Message string

    }

    func hello(w http.ResponseWriter, req *http.Request) {
    w.Header().Add("Content Type", "text/html")
    tmpl, err := template.New("anyName").Parse("index.html")
    if err == nil {
    context := Context{"Coolio", "more Go, Please"}
    tmpl.Execute(w, context)
    }
    }


    func myHanderFunc(w http.ResponseWriter, r *http.Request) {
    template.Must(template.ParseFiles("index.html")).Execute(w, hello)
    }

    func main() {
    http.HandleFunc("/", myHanderFunc)
    http.Handle("/images/", http.StripPrefix("/images/",
    http.FileServer(http.Dir("images"))))
    http.ListenAndServe(":9090", nil)
    }


    How do i update content on my site with Go?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 23, '16 at 5:43a
activeJan 23, '16 at 10:44a
posts2
users2
websitegolang.org

2 users in discussion

Volker Dobler: 1 post Gunnargeir89: 1 post

People

Translate

site design / logo © 2021 Grokbase