Skip to content

Instantly share code, notes, and snippets.

@jiaqi-yin
Last active June 10, 2021 01:07
Show Gist options
  • Save jiaqi-yin/59deafbc4283e17b0f9e216c8ef6efbc to your computer and use it in GitHub Desktop.
Save jiaqi-yin/59deafbc4283e17b0f9e216c8ef6efbc to your computer and use it in GitHub Desktop.
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