Avatar ·

How to convert interface{} to string in Go?

Hello everyone! I just started learning Go and encountered a problem when working with the `interface{}` type. I have a function that returns `interface{}`, and I need to get a regular string from this value to use it further.\n\nHere's an example code:\n\n```go\npackage main\n\nimport "fmt"\n\nfunc getValue() interface{} {\n return "Hello, World!"\n}\n\nfunc main() {\n val := getValue()\n // How to get a string from val now?\n fmt.Println(val) // Prints "Hello, World!", but val is still interface{}\n}\n```\n\nThe problem is that I cannot apply string operations to `val`. For example, trying to call `len(val)` or use `val + "!"` results in a compilation error: "invalid operation". I tried a simple type assertion: `val.(string)`, but this seems dangerous, then