与测试一起使用时,方法无法访问全局变量

I am facing problem while using Golang Testing.Global variable not accessible to methods. Following is the code snippet

test1.go

var map1 = make(map[string]string)

func f()(req *http.Request) (ismime bool, map1 map[string]string, err 
error) {
 map1["key"]="value"
return true,map1,nil
}

I am getting following errors

panic: assignment to entry in nil map [recovered]

panic: assignment to entry in nil map

From your comments it looks like you didn't really want to shadow the global variable map1, you just want to return it.

So you probably want

func f()(req *http.Request) (bool, map[string]string, error) {
    map1["key"]="value"
    return true, map1, nil
}

Returning three arguments, and a global variable among them, looks strange though. There's probably something ill designed.