Dealing public constant with internal directory

How to deal with publicly exposed constant and data structure when using internal directory?


      +---  publicAPI.go
      +---  publicHelper.go
      +---  publicConstant.go
      +---  publicDataStructure.go
      +---  ...
      +---  internal
               +--- privateAction1.go
               +--- privateAction2.go
               +--- ...

The idea was to isolate private implementations from the publicly exposed source codes. However, these
private implementations need to access the Public available constant like publicConstant.go and publicDataStructure.go.

It is understood that public imports the internal package for operations. However, if the internal imports back the public package, we get a cyclic import problem. Re-declaring public constants between the packages makes no sense in terms of maintenance.

For data structure, we can workaround by redefining the data structure type against the internal version.

1 Like

Apparently, the best choice so far:

  1. Have the value in the internal packages
  2. Have the public constants to reference the internal’s version
  3. Constant’s documentations is in public package.

There will be double declarations but both refers to the same values.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.