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

huangapple go评论79阅读模式
英文:

Why doesn't my struct code work?

问题

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
}
}

英文:
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
	}
}

I can't seem to figure out why this doesn't work. The error I get is:

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'

I don't understand, am I supposed to declare anything there?

答案1

得分: 10

type 之前,先放置你的 import

英文:

Put your import first, before the type.

huangapple
  • 本文由 发表于 2012年5月21日 15:29:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/10681063.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定