Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Define Consts for Well-Defined Values #187

Open
1 task done
c9845 opened this issue Jul 13, 2023 · 1 comment
Open
1 task done

[Feat]: Define Consts for Well-Defined Values #187

c9845 opened this issue Jul 13, 2023 · 1 comment
Labels
enhancement Introduces a new feature or improvement triage Issue is being researched

Comments

@c9845
Copy link

c9845 commented Jul 13, 2023

Feature Request Is New

  • I have verified that the requested feature does not already exist or has not already been requested.

Description of the feature

Certain fields require one of a few specific, well-defined by Easypost, values. For example, the incoterm field must be one of the following ("EXW", "FCA", "CPT", "CIP", "DAT", "DAP", "DDP", "FAS", "FOB", "CFR", and "CIF"). Currently the fields in structs just accept a string that can be one of the previously provided options or something incorrect.

Defining const would reduce the chances of users of providing unacceptable values since the user would use a const instead. This reduces typos, as well as the need to go back-and-forth between code and the API docs. Code editors would also be able to provide auto-completion hints based on the type of a struct field and the consts defined for that type.

This would not break existing code that uses strings to provide the value. The types defined as type t string would still accept "string" values instead of the consts.

Some places where this would be applicable:

  • incoterm ("EXW", "FCA", "CPT", "CIP", "DAT", "DAP", "DDP", "FAS", "FOB", "CFR", and "CIF")
  • label_format ("PNG", "PDF", "ZPL", and "EPL2")
  • payment.type ("SENDER", "THIRD_PARTY", "RECEIVER", "COLLECT")
  • duty_payment.type ("THIRD_PARTY", and "RECEIVER")
  • dropoff_type (maybe prefix the const names with FedEx as applicable).
  • deliver_confirmation
  • ...

Example:

//Define the type.
type incoterm string

//Define list of consts, with comments on separate previous line for code-editor hints, as needed...
const (
  IncotermEXW incoterm = "EXW"
)

//Modify the struct type definition...
type ShipmentOptions {
  //...
  Incoterm incoterm `json:"incoterm,omitempty"`
  //...
}

Use as...

s :=easypost.ShipmentOptions{
  Incoterm: easypost.IncotermEXW,
}

This still works...

s :=easypost.ShipmentOptions{
  Incoterm: "EXW",
}
@c9845 c9845 added the triage Issue is being researched label Jul 13, 2023
@nwithan8
Copy link
Member

Hello, thanks for the suggestion!

We've been exploring the ideas of using constants/enums in our client libraries for common values as you've suggested. It's good to know that some of our end-users would clearly benefit from their inclusion.

We'll keep you updated on our progress!

@nwithan8 nwithan8 added the enhancement Introduces a new feature or improvement label Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Introduces a new feature or improvement triage Issue is being researched
Projects
None yet
Development

No branches or pull requests

2 participants