How does go determine if key is in slice?

how is it convenient to define a slice, if you want to determine whether the key is in the slice?

The

code is as follows:
func main () {

urls := []string{
    "https://www.aaa.com",
    "https://www.bbb.com",
    "https://www.ccc.com",
    "https://www.ddd.com/",
}
fmt.Println(urls[6])  

}
output result is
panic: runtime error: index out of range

goroutine 1 [running]:
main.main ()

is there any function that can directly determine whether key is in slice?


write one yourself.

urls := make([string]struct{})

if url in urls{
    // do 
} else {
    // do 
}
Menu