compose-go icon indicating copy to clipboard operation
compose-go copied to clipboard

Improve usability of Project & Service objects

Open milas opened this issue 2 years ago • 3 comments

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 avatar Sep 06 '22 14:09 milas

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

milas avatar Sep 06 '22 14:09 milas

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

glours avatar Sep 06 '22 14:09 glours

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.

RiskyFeryansyahP avatar Sep 06 '22 15:09 RiskyFeryansyahP