kit

package module
v0.25.11 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2020 License: MIT Imports: 4 Imported by: 6

README

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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var All = utils.All

All imported

View Source
var BackoffSleeper = utils.BackoffSleeper

BackoffSleeper imported

View Source
var C = utils.C

C imported

View Source
var CD = os.CD

CD imported

View Source
var Chmod = os.Chmod

Chmod imported

View Source
var ClearScreen = utils.ClearScreen

ClearScreen imported

View Source
var Copy = os.Copy

Copy imported

View Source
var CountSleeper = utils.CountSleeper

CountSleeper imported

View Source
var DefaultBackoff = utils.DefaultBackoff

DefaultBackoff imported

View Source
var DirExists = os.DirExists

DirExists imported

View Source
var Dump = utils.Dump

Dump imported

View Source
var E = utils.E

E imported

View Source
var E1 = utils.E1

E1 imported

View Source
var Err = utils.Err

Err imported

View Source
var ErrArg = utils.ErrArg

ErrArg imported

View Source
var ErrMaxSleepCount = utils.ErrMaxSleepCount

ErrMaxSleepCount imported

View Source
var Escape = os.Escape

Escape imported

View Source
var Exec = run.Exec

Exec imported

View Source
var ExecutableExt = os.ExecutableExt

ExecutableExt imported

View Source
var Exists = os.Exists

Exists imported

View Source
var FileExists = os.FileExists

FileExists imported

View Source
var GoBin = run.GoBin

GoBin imported

View Source
var GoPath = run.GoPath

GoPath imported

View Source
var Guard = run.Guard

Guard imported

View Source
var GuardDefaultPatterns = run.GuardDefaultPatterns

GuardDefaultPatterns imported

View Source
var HomeDir = os.HomeDir

HomeDir imported

View Source
var JSON = utils.JSON

JSON imported

View Source
var KillTree = run.KillTree

KillTree imported

View Source
var Log = utils.Log

Log imported

View Source
var LookPath = run.LookPath

LookPath imported

View Source
var MergeSleepers = utils.MergeSleepers

MergeSleepers imported

View Source
var Mkdir = os.Mkdir

Mkdir imported

View Source
var Move = os.Move

Move imported

View Source
var MustGoTool = run.MustGoTool

MustGoTool imported

View Source
var MustServer = http.MustServer

MustServer imported

View Source
var MustToJSON = utils.MustToJSON

MustToJSON imported

View Source
var MustToJSONBytes = utils.MustToJSONBytes

MustToJSONBytes imported

View Source
var NewMatcher = os.NewMatcher

NewMatcher imported

View Source
var Noop = utils.Noop

Noop imported

View Source
var OutputFile = os.OutputFile

OutputFile imported

View Source
var Pause = utils.Pause

Pause imported

View Source
var RandBytes = utils.RandBytes

RandBytes imported

View Source
var RandString = utils.RandString

RandString imported

View Source
var ReadFile = os.ReadFile

ReadFile imported

View Source
var ReadJSON = os.ReadJSON

ReadJSON imported

View Source
var ReadString = os.ReadString

ReadString imported

View Source
var Remove = os.Remove

Remove imported

View Source
var RemoveWithDir = os.RemoveWithDir

RemoveWithDir imported

View Source
var Req = http.Req

Req imported

View Source
var Retry = utils.Retry

Retry imported

View Source
var RetryPanic = os.RetryPanic

RetryPanic imported

View Source
var S = utils.S

S imported

View Source
var Sdump = utils.Sdump

Sdump imported

View Source
var SendSigInt = os.SendSigInt

SendSigInt imported

View Source
var Server = http.Server

Server imported

View Source
var Sleep = utils.Sleep

Sleep imported

View Source
var Stderr = utils.Stderr

Stderr imported

View Source
var Stdout = utils.Stdout

Stdout imported

View Source
var Task = run.Task

Task imported

View Source
var Tasks = run.Tasks

Tasks imported

View Source
var TasksNew = run.TasksNew

TasksNew imported

View Source
var Try = utils.Try

Try imported

View Source
var Version = utils.Version

Version imported

View Source
var WaitSignal = os.WaitSignal

WaitSignal imported

View Source
var Walk = os.Walk

Walk imported

View Source
var WalkGitIgnore = os.WalkGitIgnore

WalkGitIgnore imported

View Source
var WalkIgnoreHidden = os.WalkIgnoreHidden

WalkIgnoreHidden imported

Functions

This section is empty.

Types

type ErrInjector added in v0.21.1

type ErrInjector = utils.ErrInjector

ErrInjector imported

type ExecContext

type ExecContext = run.ExecContext

ExecContext imported

type GinContext

type GinContext = http.GinContext

GinContext imported

type GuardContext

type GuardContext = run.GuardContext

GuardContext imported

type JSONResult added in v0.15.1

type JSONResult = utils.JSONResult

JSONResult imported

type Matcher

type Matcher = os.Matcher

Matcher imported

type MkdirOptions

type MkdirOptions = os.MkdirOptions

MkdirOptions imported

type Nil

type Nil = utils.Nil

Nil imported

type OutputFileOptions

type OutputFileOptions = os.OutputFileOptions

OutputFileOptions imported

type ReqContext

type ReqContext = http.ReqContext

ReqContext imported

type ServerContext

type ServerContext = http.ServerContext

ServerContext imported

type Sleeper added in v0.21.0

type Sleeper = utils.Sleeper

Sleeper imported

type TaskCmd

type TaskCmd = run.TaskCmd

TaskCmd imported

type TaskContext

type TaskContext = run.TaskContext

TaskContext imported

type TasksContext

type TasksContext = run.TasksContext

TasksContext imported

type WalkContext

type WalkContext = os.WalkContext

WalkContext imported

type WalkDirent

type WalkDirent = os.WalkDirent

WalkDirent imported

type WalkFunc

type WalkFunc = os.WalkFunc

WalkFunc imported

Directories

Path Synopsis
cmd
pkg
os
run

Jump to

Keyboard shortcuts

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