Coder Social home page Coder Social logo

silenceper / gowatch Goto Github PK

View Code? Open in Web Editor NEW
811.0 20.0 97.0 1.29 MB

🚀 gowatch is a command line tool that builds and (re)starts your go project everytime you save a Go or template file.

License: MIT License

Go 100.00%
inotify gowatch go automate build build-tool livereload reload hotreload golang

gowatch's People

Contributors

idontknow13 avatar jjatstash avatar picasso250 avatar silenceper avatar xinx1n avatar yanue avatar yycoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gowatch's Issues

Crashes in Docker Linux VM on MacOS+M1 due to old fsnotify

When I try to use this tool in a Linux Docker amd64 VM hosted on Mac OS with an M1 (amd64), I get a failure that inotify_init() fails. This is due to the old fsnotify dependency; updating this dependency to the latest version would fix this. I'll open a PR that should fix the problem:

建议:新增初始化gowatch.yml文件

我使用vue3+go-fiber开发,之前使用air热更新,但是air存在屏蔽日志输出和卡死进程的问题,换了gowatch后一切正常。唯一不足的是需要手动创建一个gowatch.yml文件,希望增加gowatch init命令,用于初始化一个gowatch.yml文件。

how to use in centos

silenceper你好,我按照你的说明安装了gowatch,发现根本没法直接使用gowatch命令,麻烦具体说明下,我用的是centos7系统

gowatch.yml中的cmd_args不生效

gowatch.yml文件中
例如

cmd_args:
    - -ldflags
    -  "-s -w"

经过代码阅读
我发现在gowatch.go文件的122行后增加

args = append(args, cfg.CmdArgs...)

重新编译后功能修复
另外,似乎envs等属性也没有被加载,不过我暂时没有用到所以没试
我没仔细阅读代码,也许有更好的修复方法

repository 'https://github.com/nestgo/log/' not found

Windows PowerShell
版权所有 (C) 2016 Microsoft Corporation。保留所有权利。

PS D:\WWW\blog> go get github.com/silenceper/gowatch
# cd .; git clone https://github.com/nestgo/log C:\Users\33318\go\src\github.com\nestgo\log
Cloning into 'C:\Users\33318\go\src\github.com\nestgo\log'...
remote: Repository not found.
fatal: repository 'https://github.com/nestgo/log/' not found
package github.com/nestgo/log: exit status 128
PS D:\WWW\blog>

how should i listen the tmpl files

I have a requirement to listen to tmpl files, which are in the templates folder, but I set the watch_path, but it doesn't seem to work

watch_paths:
  - templates/*

要不考虑一下做个docker容器,放在package里面,方便直接用?

可以做个Docker容器,或者完善一下Docker部分的文档(方便一下使用docker作为开发的开发者呗),这里放一个我自己用的dockerfile供参考(

感谢作者啦!

# Use Dockerfile to Build Dev Environment(support hot reload)
# Base image
FROM golang:1.22

# Set the working directory
# --------------------
WORKDIR /app

# COPY file
# --------------------
COPY go.mod .
COPY go.sum .


# Config Proxy
# --------------------
RUN go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct
# https://mirrors.aliyun.com/goproxy/,direct

# Install dependences
# --------------------
RUN go mod download
RUN export GOPATH=/go && go install github.com/silenceper/gowatch@latest && ls -al /go/bin
# go install github.com/silenceper/gowatch@latest


# Add /go/bin to PATH
# --------------------
ENV PATH=/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/go/bin

在kratos框架中使用gowatch未生效,没有启动服务。

环境:
操作系统:Win10专业版 x64
Go版本: go1.14 windows/amd64
配置文件内容:

# 当前目录执行下生成的可执行文件的名字,默认是当前目录名
appname: "demo"
# 指定编译后的目标文件目录
output: ./cmd
# 需要追加监听的文件名后缀,默认只有'.go'文件
watch_exts:
# 需要监听的目录,默认只有当前目录
watch_paths:
# 在执行命令时,需要增加的其他参数
cmd_args:
    - -conf="D:\GoCode\src\kratos-demo\configs"
# 在构建命令时,需要增加的其他参数
build_args:
# 需要增加环境变量,默认已加载当前环境变量
envs:
# 是否监听 ‘vendor’ 文件夹下的文件改变
vendor_watch: false
# 不需要监听的目录名字
excluded_paths:
# main 包路径,也可以是单个文件,多个文件使用逗号分隔
build_pkg: "./cmd/main.go"
# build tags
build_tags: ""

# 是否禁止自动运行
disable_run: false

运行信息:

2020/03/18 16:34:09 gowatch.go:77: [32m[INFO][0m Initializing watcher...
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/api )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/cmd )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/cmd/tmp )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/configs )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/dao )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/di )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/model )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/server/grpc )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/server/http )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/internal/service )
2020/03/18 16:34:09 gowatch.go:79: [32m[INFO][0m Directory( D:\GoCode\src\kratos-demo/test )
2020/03/18 16:34:09 gowatch.go:113: [32m[INFO][0m Start building...
2020/03/18 16:34:09 gowatch.go:136: [32m[INFO][0m Build Args: go build -o ./cmd ./cmd/main.go
2020/03/18 16:34:09 gowatch.go:144: [32m[INFO][0m Build was successful
2020/03/18 16:34:09 gowatch.go:174: [32m[INFO][0m Restarting ./cmd ...
2020/03/18 16:34:09 gowatch.go:184: [32m[INFO][0m Run ./cmd -conf="D:\GoCode\src\kratos-demo\configs"
2020/03/18 16:34:09 gowatch.go:187: [32m[INFO][0m ./cmd is running...

运行结果:http服务未启动

Multiple build problem on git branches

The project I'm working on has many branches that at some point are going to be merged to master, and whenever I switch branches with the application running it starts building for each modified file.

Ex.: if I change to a branch that has 100 files different from master, the application will build 100 times.

It would be nice if the application could wait, like, 1 second for files to change to build.

GOGC环境变量支持自定义传递

目前:在build时, GOGC强制设置为false。

预期:可以通过配置文件将GOGC设置为打开,因为有的时候go build不开GOGC特别费内存

How to disable DEBUG and INFO

This tool works nicely!

But there is a lot of noise in the output:

2021/11/29 08:45:26 gowatch.go:113: [INFO] Start building...
2021/11/29 08:45:26 gowatch.go:150: [INFO] Build Args: go build -o ./00
2021/11/29 08:45:26 gowatch.go:158: [INFO] Build was successful
2021/11/29 08:45:26 gowatch.go:193: [DEBUG] main pid: 6059
2021/11/29 08:45:26 gowatch.go:194: [DEBUG] pids: []
2021/11/29 08:45:26 gowatch.go:205: [DEBUG] killing MAIN process pid: 6059
❯ gowatch -v
1.5

Is there a config setting to disable the printing of DEBUG and INFO lines?
I find they take too much focus from the output from my actual program. (ERROR lines are still useful.)

Fail to watch directory[ too many open files ]

$ gowatch 

gowatch.go:77: [INFO] Initializing watcher...
gowatch.go:79: [INFO] Directory( /Users/xxx )
gowatch.go:79: [INFO] Directory( /Users/xxx )
gowatch.go:82: [ERROR] Fail to watch directory[ too many open files ]

在 配置里排除 vendor 页也是这样的


看起来有点干,还需要什么信息吗?

同时执行多条命令

如果想要在自动编译时同时执行其他命令,比如文档生成,好像是不行的,比如下面的:
swag init && go build -o app .

wsl2中好像不生效啊

操作系统:win10
子系统:wsl2 ubuntu 22.4
好像在wsl2中gowatch无法运行我的程序啊
我用go run main.go就可以运行
1699703017754
到./ is running...这一步就不动了
用go run main.go就正常了
image

Shouldn't it watch for changes to gomod?

If i add a replace directive to the go mod, why does it not recompile?
It'd make sense to have a flag for this, or to automatically do that, instead of having to have a whole config file just for specifying the go.mod file... and i don't even know if putting the file into that config works... haven't tried it, not gonna.
Just a wee bit annoying.
That being said, thanks for the tool!

not restart the application

I have modified the file,but nothing changed.I dont know what is the problem, Could you tell how to deal with it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.