Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Codersdk: make workspace_build.deadline a pointer #2015

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

Closed
Tracked by #1317
johnstcn opened this issue Jun 3, 2022 · 1 comment · Fixed by #3552
Closed
Tracked by #1317

Codersdk: make workspace_build.deadline a pointer #2015

johnstcn opened this issue Jun 3, 2022 · 1 comment · Fixed by #3552
Assignees
Labels
api Area: HTTP API
Milestone

Comments

@johnstcn
Copy link
Member

johnstcn commented Jun 3, 2022

What

Change this

type WorkspaceBuild struct {
    ...
    Deadline time.Time `json:"deadline"`
    ...

To this:

type WorkspaceBuild struct {
    ...
    Deadline *time.Time `json:"deadline"`
    ...

Why

The FE currently needs to check for the zero-value of time.Time for 'falsey' values.
Making this a pointer would allow passing null and avoid this need.

@johnstcn johnstcn changed the title refactor: codersdk: make workspace_build.deadline a *string refactor: codersdk: make workspace_build.deadline a pointer Jun 3, 2022
@misskniss misskniss added this to the Community MVP milestone Jun 3, 2022
@kylecarbs kylecarbs changed the title refactor: codersdk: make workspace_build.deadline a pointer Codersdk: make workspace_build.deadline a pointer Jun 7, 2022
@kylecarbs kylecarbs added the chore label Jun 7, 2022
@mafredri
Copy link
Member

mafredri commented Jun 10, 2022

Since we're starting to have quite a few pointers, I would suggest two options:

  1. Start using type Null[Type] struct types where Valid is set to true/false
  2. Separate the fields so that there is Deadline time.Time and DisableDeadline bool (as an example)

For 1. we could either maintain our own package of types used by the API, or rely on pre-existing work. One example is https://github.com/guregu/null/blob/21596e8e52a426a14cd73b22f6ffa4d31165302f/time.go#L12-L16. These would support JSON (de-)marshaling and be slightly safer to use than pointers (and dereferencing).

For 2. first I would like to ask: Why does the frontend need to pass null vs undefined? If we don't care about changing the value (disable), then undefined should be just fine. In TypeScript this would simply read deadline?: string which matches the API contract when using JSON omitempty (edit: Time might require a custom json marshaler to be omitted though, but I think that'd be worthwhile over using a pointer).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Area: HTTP API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants