How to get the last path segment of a URL in Go

To get the last path segment of a URL in Go, you can use the path.Base() method from the standard library.

func main() {
	fmt.Println(path.Base("https://freshman.tech/file.jpg")) // file.jpg
	fmt.Println(path.Base("https://freshman.tech/test")) // test
}

Thanks for reading, and happy coding!