I wanna get and set cookie in my service file, but the code "ctx.SetCookie()" always get error "invalid memory address or nil pointer dereference", please help me, thanks in advance

I have tried two methods to deal this problem,but there is still something wrong with it 

method 1:

```
type security struct {
    beego.Controller
}
...
func (s security) CheckToken(){
    ...

    ctx.SetCookie("token","xxxxxxxx")
}

```

methos 2:

```
import "github.com/astaxie/beego/context"

func (s security) CheckToken(){
    ...
    ctx := context.NewContext()
    ctx.SetCookie("token","xxxxxxxx")
}

```

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x832639]