route怎么用? go语言页面的a链接跳转如和实现啊。 这用的是github无闻的代码,我想知道怎么实现页面内a链接跳转~~~

package main

import (
    "fmt"
    "html/template"
    "log"
    "net/http"
    "os"
    "path/filepath"
)

type Package struct {
    Name     string
    NumFuncs int
    NumVars  int
}

func main() {

    wd, err := os.Getwd()
    if err != nil {
        log.Fatalf("Getwd: %v", err)
    }
    log.Print("Work directory:", wd)

    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        // tmpl := template.Must(template.ParseFiles(filepath.Join(wd, "main_v2.tmpl")))
        tmpl, err := template.ParseFiles(filepath.Join(wd, "info.html"))
        if err != nil {
            fmt.Fprintf(w, "ParseFiles: %v", err)
            return
        }
        err = tmpl.Execute(w, &Package{
            Name:     "go-web",
            NumFuncs: 12,
            NumVars:  1200,
        })
        if err != nil {
            fmt.Fprintf(w, "Execute: %v", err)
            return
        }
    })

    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) // 启动静态文件服务
    log.Print("Starting server...")
    log.Fatal(http.ListenAndServe(":80", nil))
}

共 0 个回复