0

let say a function

func BuildRequest(string,string,string)

all three parameters are optional

`request, err := BuildRequest("","{}","")` --> incorrect 

like in JS, Java, Python we have null, None but in golang nil is not from string family.

How can I solve this?

0xSHA1001
  • 59
  • 1
  • 11

1 Answers1

0

If that is the signature of the function (the signature is given), then it depends entirely on the implementation of the function. Most likely the empty string will represent the lack of actual argument value.

If you're free to choose the parameter type, then *string may be nil to represent null value. Or if you don't use the empty string value, denote that to be null and you may use string for convenience

See possible duplicates:

How do I represent an Optional String in Go?

How to Return Nil String in Go?

icza
  • 389,944
  • 63
  • 907
  • 827