2012-05-21 36 views
3
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' 

我不明白,我應該聲明什麼嗎?

回答

10

把你的import先,type之前。

+0

似乎工作。去肯定比我最初想象的更難。 – Bogdacutu

+4

這並不困難;我建議先嚐試在本地開發事物,然後是GAE。你會對事物有更好的感覺。 – Ashe