Web Development

Contains is a function from the String Package of Go Lang. Contains, however, is case sensitive.

package main

import (
  "fmt"
  "strings"
)

func main() {
   fmt.Println("Contains", strings.Contains("Hello", "hell"))
   fmt.Println("Contains", strings.Contains("hello", "hell"))
}
Output
$ go run contains.go 
Contains false
Contains true

Let’s create a function that you would need for a case-insensitive Contains functionality

package main

import (
  "fmt"
  "strings"
)

func caseInsenstiveContains(a, b string) bool {
  return strings.Contains(strings.ToUpper(a), strings.ToUpper(b))
}

func main() {
   fmt.Println("Contains", caseInsenstiveContains("Hello", "hell"))
   fmt.Println("Contains", caseInsenstiveContains("hello", "hell"))
}
Output
$ go run case_insensitive.go 
Contains true
Contains true

Voila! a case-insensitive Contains method