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

Improve usability of Project & Service objects #305

Open
milas opened this issue Sep 6, 2022 · 3 comments
Open

Improve usability of Project & Service objects #305

milas opened this issue Sep 6, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@milas
Copy link
Member

milas commented Sep 6, 2022

Description

The Project and Service objects returned by this library often
confuse users because certain fields are not always initialized.

For example, CustomLabels (a map[string]string) will be nil
on each Service.

Potential Solutions

  • Add NewProject and NewService constructors that initialize
    all fields consistently
  • Add helper methods, e.g. AddCustomLabel that internally handle
    initialization lazily

Related Issues

docker/compose#9808

@milas milas added the enhancement New feature or request label Sep 6, 2022
@milas
Copy link
Member Author

milas commented Sep 6, 2022

cc @glours I know we talked about this before around another Compose PR, so you might remember some other cases we should track here

@glours
Copy link
Contributor

glours commented Sep 6, 2022

Users should add new elements to this kind of Map with the helper Add function that checks if the map is empty or not before adding a new value.

Anyway we can create a generic function for that as Golang 1.19 is out.
Golang 1.17 is not supported anymore so we may assume downstream projects to use at least Golang v1.18.x

@RiskyFeryansyahP
Copy link

Hello guys, sorry for joining the discussion here 🙏 .

how about on LoadService we add the process to initialize the CustomLabel to the empty value of map[string]string instead of leaving it nil ?
because most who use this compose-go library call it in loader.Load(). so when loader.Load() return the Project type the value of Service.CustomLabel not nil but already initialize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants