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?

1
  • Use *string for optionals. Commented Apr 12, 2020 at 19:34

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.