j6s / mailcow-exporter

MIT License
56 stars 12 forks source link

Suggestion: export MAILCOW_EXPORTER_SCHEME as variable #18

Open ottobaer opened 4 months ago

ottobaer commented 4 months ago

Hi,

Since I'm using the docker container on a host that runs the mailcow (api) on an internal IP, it would be nice to be able to declare scheme as a variable, since https it not usable if it's a private IP.

export MAILCOW_EXPORTER_SCHEME="https" 

or

export MAILCOW_EXPORTER_SCHEME="http" 

I have looked into the sources, but I don't know go well enough to make a pull request.

j6s commented 4 months ago

This is a good idea and I am confused, why this hasn't come up earlier. Unfortunately, I am currently flooded with work, so It's going to be a good bit until I can find some time for it. In case you want to get familiar with go a bit, all of the necesarry pieces should be in main.go.

If you have a go compiler installed, then you should be able to use make build in order to build the project into the bin/ directory. If you have any questions about the process, feel free to reach out.

j6s commented 4 months ago

Looking at the code a bit more, the preferred solution would probably be

ottobaer commented 4 months ago

I just had a go at, but it won't compile because of an undefined variable - here I'm a bit lost because of go.

./main.go:131:13: undefined: defaultScheme
make: *** [Makefile:6: build] Error 1

If I understand it right defaultScheme gets declared and set to "https" - I'm missing something here I guess.


    defaultScheme, _ := os.LookupEnv("MAILCOW_EXPORTER_SCHEME")
    if defaultScheme == "" {
        defaultScheme = "https"
    flag.StringVar(&scheme, "scheme", defaultScheme, "Default connection scheme. Defaults to the MAILCOW_EXPORTER_SCHEME environment variable or 'https' otherwise")
            scheme = defaultScheme 
ottobaer commented 4 months ago

Hi,

Finally got around to take some time to read through the code and learn some go on the way. I created a PR, feel free to look into it when you have time.

Thank You,