I want to load the library created by Go on the private repository, but I'm having a problem because I don't know how to set the file path such as fonts on the library side.

Since the library is used by go.mod, it is necessary to set the file path according to the library user side.
Until now, the following measures have been taken, but they could not be read.

  • I tried to read by specifying a relative path from the place used in the library
  • In the libraryos.getcwd ()I thought that I could get the current path of the library if I used, but I got the current path of the library user side

Please let me know if there is a way to read the files that exist in the library in the library ... Thank you.

  • Answer # 1

    Go is a compiled processing system, so if you refer to the files included in the library, you will have to install the library in the execution environment.
    Furthermore, if the library is in a private repository, go-get is not possible.
    It requires its own distribution procedure. There is a way to get the library path, but we don't recommend using it.

    Strategy 1

    As a means to take, distribute the font file and the compiled executable file, put the font file near the executable file, and get the font file path with the following code.

    exe, err: = os.Executable ()
    fontPath: = filepath.Join (filepath.Dir (exe), "font file name")

    Disadvantages of this method

    Doesn't work well when run with go run

    Just go-getting the library doesn't work

    Strategy 2

    Convert the font file to go code and embed it in the library.
    Consider using the following bundle tools and libraries.




    This method can be used by go-get, but the executable file tends to be large.