Why won't this default in a switch ever be called?

I wrote this code and I’m getting an error that this fmt.Errorf line would never be used. All the other cases seem to match up correctly but when I give command a value that doesn’t match…shouldn’t it fall through?

		switch {
		case strings.EqualFold("WRITE", command):
			fmt.Println("WRITING!")
		case strings.EqualFold("READ", command):
			fmt.Println("READING!")
		case strings.EqualFold("START", command):
			fmt.Println("STARING!")
		case strings.EqualFold("DELETE", command):
			fmt.Println("DELETING!")
		case strings.EqualFold("COMMIT", command):
			fmt.Println("COMMITTING!")
		case strings.EqualFold("ABORT", command):
			fmt.Println("ABORTING!")
		case strings.EqualFold("QUIT", command):
			fmt.Println("QUITTING!")
		default:
			fmt.Errorf("NO MATCH")
		}

Well, I got my answer.

fmt.Errorf returns a value. DUH.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.