danieljancar / proxy-request-checker

Checks provided whitelists, blacklists, etc. for your proxy configuration by making requests to the provided links.
MIT License
1 stars 0 forks source link

When running the binary, the report is not saved to the specified file path, also the links.json file is not found #3

Open danieljancar opened 8 months ago

danieljancar commented 8 months ago

Check List

Description

When running the built binary of the program, it can't find the links.json because it's ran from a different path then the project root, also it can't export the report.json.

Steps to Reproduce

Build executable binary from your local project, try to execute from terminal or GUI.

Expected Behavior

Should work as intended when running with go run cmd/main.go

Actual Behavior

Throws error and fails reading/exporting files

Additional Info

-

rkruetli commented 7 months ago

I'll have a look into it, strange that the binary version behafes different... as fare as I know is go run also compiled and executed...

danieljancar commented 7 months ago

Hey @rkruetli

I'll have a look into it, strange that the binary version behafes different... as fare as I know is go run also compiled and executed...

You're right, when running the built binary from the project's root, it works. Sadly, when moving the executable proxy-checker.exe to another folder or executing it from a different path, it obviously can' find the config or report folder which is found at the project's root. So either, running the binary from somewhere else isn't an option or we need to implement a workaround.


Success

  1. Building a binary from project root
$ go build -o proxy-checker cmd/main.go
  1. Executing the proxy-checker from project root, since it got saved there
    $ ./proxy-checker 
    2024/01/15 11:32:16 Requesting https://google.com
    2024/01/15 11:32:16 Requesting https://dev.to
    2024/01/15 11:32:16 Requesting https://css.ch
    2024/01/15 11:32:16 Requesting https://slack.com

Fail

  1. Fails when running the binary from different path then project root

    $  ./go-proxy-request-checker/proxy-checker 
    2024/01/15 11:38:34 Error reading json file: open config/links.json: no such file or directory. Using default values...
    2024/01/15 11:38:34 Requesting https://www.google.com
    2024/01/15 11:38:34 Requesting https://www.slack.com

Solution