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

标签 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'

我不明白,我应该在那里申报什么吗?

最佳答案

将您的import放在type之前。

关于struct - 为什么我的结构代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10681063/

相关文章:

c++ - 将 char 复制到结构指针 char

C# 比较 3 字节字段

string - 调用fmt.Printf(“%+ v”,obj)时如何自定义结构的特定文件的文本

go - 无法进行查询API调用,ResourceNotFoundException:无法对不存在的表执行操作

go - map[string]interface{} 的类型嵌套映射返回 "type interface {} does not support indexing"

go - 如何避免恼人的错误 "declared and not used"

c - 赋值中的类型不兼容,为什么我不能这样做?

c - 在不同的函数中访问结构内的结构

pointers - 何时使用指针

algorithm - 如何计算非零值的加权平均值?