All Projects → ysmood → kit

ysmood / kit

Licence: MIT license
A collection of often-used IO related methods

Programming Languages

go
31211 projects - #10 most used programming language

Kit

GoDoc codecov goreport

This project is a collection of often-used io related methods with sane defaults to make coding less verbose.

Modules

os

Covers most used os related functions that are missing from the stdlib.

Such as the smart glob that handles git ignore properly:

package main

import "github.com/ysmood/kit"

func main() {
    kit.Log(kit.Walk("**/*.go", "**/*.md", kit.WalkGitIgnore).MustList())
}

A better Exec alternative:

package main

import "github.com/ysmood/kit"

func main() {
    kit.Exec("echo", "ok").MustDo()

    str := kit.Exec("echo", "ok").MustString()

    kit.Log(str)
}

http

The http lib from stdlib is pretty verbose to use. The kit.Req is a much better alternative to use with its fluent api design. It helps to reduce the code without sacrificing performance and flexibility. No api is hidden from the origin of http lib.

package main

import "github.com/ysmood/kit"

func main() {
    val := kit.Req("http://test.com").Post().Form(
        "search", "keyword",
        "even", []string{"array", "is", "supported"},
    ).MustJSON().Get("json.path.value").String()

    kit.Log(val)
}
package main

import "github.com/ysmood/kit"

func main() {
    server := kit.MustServer(":8080")
    server.Engine.GET("/", func(ctx kit.GinContext) {
        ctx.String(200, "ok")
    })
    server.MustDo()
}

CLI tool

Goto the release page to download the executable for your OS. Or install with single line command below.

godev

A general dev tool for go project to lint, test, build, deploy cross-platform executable.

godev will release your project to your own github release page. Project released with godev can be installed via this shell script. godev itself is an example of how to use it.

Install godev: curl -L https://git.io/fjaxx | repo=ysmood/kit bin=godev sh

usage: godev [<flags>] <command> [<args> ...]

dev tool for common go project

Flags:
  --help                     Show context-sensitive help (also try --help-long
                             and --help-man).
  --version                  Show application version.
  --cov-path="coverage.txt"  path for coverage output

Commands:
  help [<command>...]
    Show help.

  test* [<flags>] [<match>]
    run go unit test

  lint [<path>...]
    lint project with golint and golangci-lint

  build [<flags>] [<pattern>...]
    build [and deploy] specified dirs

  cov
    view html coverage report


guard

Install guard: curl -L https://git.io/fjaxx | repo=ysmood/kit bin=guard sh

usage: guard [<flags>]

run and guard a command, kill and rerun it when watched files are modified

  Examples:

   # follow the "--" is the command and its arguments you want to execute
   # kill and restart the web server when a file changes
   guard -- node server.js

   # use ! prefix to ignore pattern, the below means watch all files but not those in tmp dir
   guard -w '**' -w '!tmp/**' -- echo changed

   # the special !g pattern will read the gitignore files and ignore patterns in them
   # the below is the default patterns guard will use
   guard -w '**' -w '!g' -- echo changed

   # support go template
   guard -- echo {{op}} {{path}} {{file}}

   # watch and sync current dir to another machine
   guard -n -- rsync {{path}} root@host:/home/me/app/{{path}}
   guard -n -- docker cp {{path}} my-container:/app/{{path}}

   # the patterns must be quoted
   guard -w '*.go' -w 'lib/**/*.go' -- go run main.go

   # the output will be prefix with red 'my-app | '
   guard -p 'my-app | @red' -- python test.py

   # use "---" as separator to guard multiple commands
   guard -w 'a/*' -- ls a --- -w 'b/*' -- ls b


Flags:
      --help             Show context-sensitive help (also try --help-long and
                         --help-man).
  -w, --watch=WATCH ...  the pattern to watch, can set multiple patterns
  -d, --dir=DIR          base dir path
  -p, --prefix="auto"    prefix for command output
  -c, --clear-screen     clear screen before each run
  -n, --no-init-run      don't execute the cmd on startup
      --poll=300ms       poll interval
      --debounce=300ms   suppress the frequency of the event
      --raw              when you need to interact with the subprocess
      --version          Show application version.

You can also use it as a lib:

package main

import "github.com/ysmood/kit"

func main() {
    kit.Guard("go", "run", "./server").ExecCtx(
        kit.Exec().Prefix("server | @yellow"),
    ).MustDo()
}

Test & Build

See the Github Actions config in this project.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].