Converting a custom type to string in Go

前端 未结 5 2070
感动是毒
感动是毒 2020-12-14 15:36

In this bizarre example, someone has created a new type which is really just a string:

type CustomType string

const (
        Foobar CustomType = \"somestr         


        
5条回答
  •  失恋的感觉
    2020-12-14 16:33

    answering this for anyone who comes here searching. You can convert the type to string on return using fmt.Sprintf

    click here to see it in action

    func SomeFunction() string {
        return fmt.Sprintf("%v", Foobar)
    }
    

提交回复
热议问题