Skip to content

Commit 57a83cc

Browse files
committed
Update README for autoreloader command
Adds description for installation and demo
1 parent 0f89cd8 commit 57a83cc

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

README.md

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
# autoreload
44

5-
`autoreload` provides a package for automatically reloading an executable when that executable changes. It intended to be used in a local development environment to reload the executable after it has been modified as part of the development process. An example use case, would be to reload a go web app after you have edit the source code and recompiled the executable.
5+
`autoreload` provides a package or command for automatically reloading an executable when that executable changes. It intended to be used in a local development environment to reload the executable after it has been modified as part of the development process. An example use case, would be to reload a go web app after you have edit the source code and recompiled the executable.
66

77
## Installation
88

9-
`autoreload` can be used as a package that is integrated into your application:
9+
`autoreload` can be used as a package that is integrated into your application or as a command that is supplied an executable to monitor.
10+
11+
### Installation via Package
12+
13+
To integrate the package into your application, follow the example below.
1014

1115
```
1216
package main
@@ -25,3 +29,77 @@ func main() {
2529
```
2630

2731
See the [provided example](https://github.com/agschwender/autoreload/blob/main/example/main.go) for greater detail on how to integrate the package into your application.
32+
33+
### Installation via Command
34+
35+
To integrate the command into your application, you must first install the `autoreload` command:
36+
37+
```
38+
$ go install github.com/agschwender/autoreload/autoreloader@v1.1.0
39+
```
40+
41+
Once installed, you can then execute the command by supplying it with the executable you want it to monitor and restart. For example if you wanted to run your server command, it may look like this:
42+
43+
```
44+
$ autoreloader server --port=8080
45+
```
46+
47+
## Demo
48+
49+
You can verify the behavior of the package or command installation by using the provided `example` command.
50+
51+
In one terminal, compile the commands
52+
53+
```
54+
$ go install ./...
55+
```
56+
57+
In another terminal, run
58+
59+
```
60+
$ example
61+
2022/11/18 10:06:43 Starting application
62+
2022/11/18 10:06:43 Auto-reload is enabled
63+
2022/11/18 10:06:43 Starting HTTP server
64+
```
65+
66+
Change the `example/main.go` file and then re-install, using the first terminal
67+
68+
```
69+
$ go install ./...
70+
```
71+
72+
You should see the reload happen in your second terminal
73+
74+
```
75+
2022/11/18 10:06:57 Executable changed; reloading process
76+
2022/11/18 10:06:57 Received change event, shutting down
77+
2022/11/18 10:06:58 Starting application
78+
2022/11/18 10:06:58 Auto-reload is enabled
79+
2022/11/18 10:06:58 Starting HTTP server 2
80+
```
81+
82+
Similarly, you can run via the `autoreloader` with the `example` commands build in reloading turned off.
83+
84+
In your second terminal, run
85+
86+
```
87+
$ autoreloader example --autoreload=false
88+
2022/11/18 10:10:11 Starting application
89+
2022/11/18 10:10:11 Starting HTTP server
90+
```
91+
92+
Again make a change to the `example/main.go` file and then re-install, using the first terminal
93+
94+
```
95+
$ go install ./...
96+
```
97+
98+
You should see the reload happen in your second terminal
99+
100+
```
101+
2022/11/18 10:11:08 Executable changed; reloading process
102+
2022/11/18 10:11:09 Killing process
103+
2022/11/18 10:11:09 Starting application
104+
2022/11/18 10:11:09 Starting HTTP server 2
105+
```

0 commit comments

Comments
 (0)