具有多个UI的工具的项目结构

I'm playing with golang and made a tool for password generation. Initially it was intended to be used as a command line tool. I later separated the generation logic into a separate package (still same github repository) and left the main function in the root of the project. Now I also want to add a simple web frontend (nothing fancy), but I don't know how to structure the packages.

Am I supposed to put both the command line entry point as well as the web UI into their own packages in the same project (which leaves the root empty). Or maybe I should move the actual generation library to the root and the UIs in separate packages. I guess the other option is to have the UIs in separate projects on github, but they are only going to be used for this library, so it does not seem like a good idea.

I remember seeing in some projects packages named cmd for example, but never have I encountered one, with multiple front ends. Is there a go(-gettable-)way for doing this?

I agree that there's not much point in making separate projects/repositories if they're only going to be used for this library. I would just have a cmd directory with a subdirectory for each executable you're building.

Something like this:

  • github.com/user/project
    • generation
    • cmd
      • cmdline
        • main.go
      • web
        • main.go

The main.go files can use the functionality that you've broken out into your "generation" package.

The name of the executables produced by go build will be the name of the parent directory, so cmdline and web in this example (you would want to choose better names).

Note: you don't actually have a package cmdline or web. The files in those directories would all be in [their own separate] package main.