Last active
June 10, 2021 01:07
-
-
Save jiaqi-yin/59deafbc4283e17b0f9e216c8ef6efbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
func makeSuffix(suffix string) func(string) string { | |
return func(fileName string) string { | |
if strings.HasSuffix(fileName, suffix) { | |
return fileName | |
} | |
return fileName + "." + suffix | |
} | |
} | |
func main() { | |
f := makeSuffix("jpg") | |
fmt.Println(f("hello.jpg")) | |
fmt.Println(f("world")) | |
fmt.Println(f("text.txt")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment