Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package main
import (
func main() {
x := generateMessage("Hello {0}, you have {1} new messages!", "Gerep", "12")
func generateMessage(m string, p ...interface{}) string {
for k, v := range p {
i := strconv.Itoa(k)
m = strings.Replace(m, "{"+i+"}", fmt.Sprintf("%s", v), -1)
return m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment