为什么我的结构代码不起作用?

时间:2012-05-21 07:29:08

标签: struct go

package app

type ConfigSet struct {
    installed bool
}

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

func init() {
    config := ConfigSet{}

    // -------------------------------------- //
    //             CONFIGURATION              //
    // -------------------------------------- //

    // Change to "true" after configuration is done!
    config.installed = false

    // -------------------------------------- //
    //           END CONFIGURATION            //
    // -------------------------------------- //

    http.HandleFunc("/", index)
    http.HandleFunc("/index.php", index)
}

func index(w http.ResponseWriter, r *http.Request) {
    if config.installed == false {
        w.Header().Set("Location", "/install/")
        return
    }
}

我似乎无法弄清楚为什么这不起作用。我得到的错误是:

2012/05/21 13:22:01 go-app-builder: Failed parsing input (1 error)
2012/05/21 13:22:01 /root/TravianGAE/app/app.go:7:1: expected declaration, found 'import'

我不明白,我应该在那里宣布什么?

1 个答案:

答案 0 :(得分:10)

import放在type之前。