You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+80-2Lines changed: 80 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,15 @@
2
2
3
3
# autoreload
4
4
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.
6
6
7
7
## Installation
8
8
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.
10
14
11
15
```
12
16
package main
@@ -25,3 +29,77 @@ func main() {
25
29
```
26
30
27
31
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
0 commit comments