切换或运算符编译错误

时间:2015-03-02 10:01:50

标签: go

我有以下编译器抱怨的代码。

switch req.Method {
        case "POST" || "PUT" || "DELETE":
            if req.Header.Get("Content-Type") != "application/json" {
                return handleErr(req)
            }
    }

编译器错误消息

..\..\controllers\routes\header.go:59: invalid operation: "POST" || "PUT" (operator || not defined on string)

我是否以错误的方式使用OR运算符?

1 个答案:

答案 0 :(得分:3)

只需使用逗号,代替||

case "POST", "PUT", "DELETE":

请参阅switch statement reference