pjx

command module
v0.0.0-...-64c5b57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2020 License: MIT Imports: 17 Imported by: 0

README

pjx

pjx is a tool helps auto-generate server side directories and some go code.Supporting linux, windows, mac.

Table of Contents generated with DocToc

1. Start

GOPATH

way 1:

  • go get -u github.com/fwhezfwhez/pjx

way 2:

  • git clone https://github.com/fwhezfwhez/pjx.git
  • cd pjx
  • go install
GOMODULE
  • git clone https://github.com/fwhezfwhez/pjx.git
  • go install

Make sure in cmd type pjx --version, output normal.

2. Module

pjx now provides functional flows below:

2.1 Directory generate

For developing golang server project, pjx can auto-generate projects.

Take helloWorld project for example:

pjx new helloworld

cd helloworld

pjx module user

The generated directories will look like:

appName
  | -- module
  | -- config
  | -- dependence
  | -- independence
  | -- main.go

What are they?

  • appName: project name, for example helloWorld
  • module: all modules about service, for example user, shop. Each module has inner directories.They're documented below.
  • config: some config of the project.
  • dependence: packages or files of common util tool. These packages and files might import project's inner package.
  • independence: packages or files of common util tool. These pkg and files will not import any of this project.It can be no-harm add, remove, reuse-copy.
  • main.go: project entrance.

module

Module divides project into modules such as user, shop.Its generated directories will look like:

module
  | -- user
  |     | -- userPb
  |     | -- userModel
  |     | -- userRouter
  |     | -- userService
  |     | -- userTestClient
  |     | -- userExport
  |     | -- userControl
  |     | -- userJob
  |     | -- main.go
  | ...

What are they?

  • user: module name.
  • userPb: proto file and generated go file.
  • userModel: db model or service model.
  • userRouter: http, tcp router.
  • userControl: place to receive request body from router, also a place to handle error.
  • userService: http, tcp service codes.Errors from here will be return.
  • userTestClient: generate test as client codes.
  • userExport: export user module as another single server.It's a sub-node of user/main.go
  • userJob: cron jobs.

Commands are below:

  • pjx new appName
  • pjx module moduleName

Design your own directories refers to 4.2. How to design module directories as wanted?

// - pjx test-client functionName [--http] [--tcp] [--grpc]

2.2 Package storage and migration

Make sure configure system env pjx_path.This will let pjx know where to storage package locally

For storing and migrating local package, pjx provides commands below:

Take helloworld for example:

pjx add helloworld add a package named helloword in current dir into repo

pjx use helloworld insert a package from repo to current dir

Make sure configure system env pjx_path.This will let pjx know where to storage package locally.If not well set, it still work and will save packages in user-home/pjx_path

add and use keyword ruled below:

(value in '<>' is necessary, '[]' is optional. if namespace, tag not set, use 'global' and 'master'. ':value' means it's a value not fixed.)

pjx add <packageName> [:namespace] [:tag] [-f] it will add a package in current dir into repo ${pjx_path}/:namespace/:package-name@:tag.Optional args:

  • -f force add package, if exist, replace old.

pjx use <packageName> [:namespace] [:tag] [-o :rename] it will insert a package from repo into current dir.Optional args:

  • -o add package with another name.
2.3 Config files encrypt and decrypt

refer to https://github.com/fwhezfwhez/pjx/tree/master/modules/encrypt-decrypt

3. Commands

3.1 new

pjx new <appName> new a project

pjx new hello
3.2 module

pjx module <moduleName> [-m <key>] using specific template to generate module.

pjx module user
pjx module shop -m test
3.3 add

pjx add <packageName> [namespace] [tag] [-f] add package into repo(at ${pjx_path}). If pjx_path not set, they will be stored in user-home/pjx_path.

pjx add hello // package hello will be add into pjx_path/global/hello
pjx add hello fwhezfwhez master// package hello will be add into pjx_path/fwhezfwhez/hello
pjx add hello global tmp // package hello will be add into pjx_path/global/hello@tmp
3.4 use

pjx use <packageName> [namespace] [tag] [-o <rename>] use a package from repo and insert to current dir.If pjx_path not set, use pjx_path default user-home/pjx_path.

pjx use hello // use pjx_path/global/hello and insert to current dir.
pjx use hello fwhezfwhez tmp -o hello2 // use pjx_path/fwhezfwhez/hello@tmp and insert into current dir with name hello2
3.5 merge

pjx merge <path> <namespace> [-f/-u] merge all packages in path into namespace

pjx merge /home/web/repo global -f // copy all /home/web/repo's sub dir into pjx_path/global, if exists, replace the old.
pjx merge /Users/web/repo fwhezfwhez -u // copy all /Users/web/repo's sub dir into pjx_path/fwhezfwhez, if exists, jump this.
3.6 clone

**need install git. type git --version has well output** pjx clone url.git [-u/-f]` clone a remote repo,and copy all sub dir in it to pjx_path/

pjx clone https://github.com/fwhezfwhez/pjx-repo.git global -u  jump the existing case
pjx clone https://github.com/fwhezfwhez/pjx-repo.git global -f  replace the existing old
3.7 encrypt, decrypt

encrypt config files and decrypt.

pjx encrypt *.json encrypt config files into old_name.crt

pjx decrypt *.crt decrypt config files ended with .crt back

4. Optional args

value meaning example why scope
-l open log pjx add xxx -l show log all
-f add package by force pjx add xxx -f avoid package exist error add, merge, clone
-o use package in another name pjx use xxx -o xxx2 avoid package exist error use
-m choose module template,it's at 'pjx/module-template.go' pjx module user -m test to design module directories as wanted module
-u jump existed package with the same name when meet command merge and clone PJX merge g:/repo fwhezfwhez -u avoid package exist error merge, clone

5. FAQ

5.1. pjx command not found?

go get -u ... or go install will put pjx execute file into ${GOPATH}/bin. Make sure your ${GOPATH}/bin is in your system path.

5.2. How to design module directories as wanted?

If you don't like xRouter, xService... this kind of directories, you can just modify module-template.go.By default, there is two keys default and test to refer the template.Pjx will choose as below:

  • pjx module user using default key,and generate xRouter,xService,xModel,xPb,xTestClient,xExport
  • pjx module user -m test using test key, and generate xModel,xService,xRouter.

After you modify module-template.go, don't forget to run go install to refresh pjx command

5.3. Permission deny?

Make sure the spot you execute pjx has proper permission. For instance, when you execute pjx add xx, you must has read permission to the package xx and write permission to pjx_path.This kind of question should never depend on pjx to fix it.

5.4. Pjx-repo for sharing?

Here is my personal repo sharing.It might change by time and might have dependency.But their usage will be easy and with specific doc. https://github.com/fwhezfwhez/pjx-repo

5.5. Add modules in specific folder whose name is not 'module'?
# add module 'order' into your folder.
pjx module order -p 'your-folder-name'

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL