sessions icon indicating copy to clipboard operation
sessions copied to clipboard

Test code error

Open ggaaooppeenngg opened this issue 11 years ago • 2 comments
trafficstars

In the Test_SessionsDeleteValue

    m.Get("/show", func(session Session) string {
        if session.Get("hello") == "world" {
            t.Error("Session value deleting failed")
        }
        return "OK"
    })

Get("hello") return interface of hello and it would never equals to string "world"。

ggaaooppeenngg avatar Mar 31 '14 13:03 ggaaooppeenngg

sorry for this post i tried the code package main

import (
    "fmt"
)

func main() {
    var a interface{}
    a = "haha"
    fmt.Println(a=="haha")
}

it works ok,but how can a interface{} equals to a string?

ggaaooppeenngg avatar Mar 31 '14 16:03 ggaaooppeenngg

http://golang.org/ref/spec#Comparison_operators

In any comparison, the first operand must be assignable to the type of the second operand, or vice versa.

A value x of non-interface type X and a value t of interface type T are comparable when values of type X are comparable and X implements T. They are equal if t's dynamic type is identical to X and t's > dynamic value is equal to x.

http://golang.org/ref/spec#Types

Variables of interface type also have a distinct dynamic type, which is the actual type of the value stored in the variable at run time.

patricksuo avatar Jun 08 '14 03:06 patricksuo