-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom watchers allow defining custom file change handlers. A common case for those are JavaScript files that you might want to bundle. Another common usecase would be requiring a server restart on config file changes. fix: Handle WebSocket connection closure properly to avoid leaking websocket handler goroutines. fix: Abort health-check after restart when a termination signal was received. fix: Add space between prefix and body in package `internal/log`.
- Loading branch information
Showing
19 changed files
with
1,028 additions
and
619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Package action provides a simple helper for consolidating custom watcher actions. | ||
package action | ||
|
||
import "sync" | ||
|
||
// Type is an action type. | ||
type Type int8 | ||
|
||
const ( | ||
// ActionNone requires no rebuild, no restart, no reload. | ||
ActionNone Type = iota | ||
|
||
// ActionReload requires browser tab reload. | ||
ActionReload | ||
|
||
// ActionRestart requires restarting the server. | ||
ActionRestart | ||
|
||
// ActionRebuild requires rebuilding and restarting the server. | ||
ActionRebuild | ||
) | ||
|
||
// SyncStatus action status for concurrent use. | ||
type SyncStatus struct { | ||
lock sync.Mutex | ||
status Type | ||
} | ||
|
||
// Require sets the requirement status to t, if current requirement is a subset. | ||
func (s *SyncStatus) Require(t Type) { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
if t > s.status { | ||
s.status = t | ||
} | ||
} | ||
|
||
// Load returns the current requirement status. | ||
func (s *SyncStatus) Load() Type { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
return s.status | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package action_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/romshark/templier/internal/action" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRequire(t *testing.T) { | ||
var s action.SyncStatus | ||
require.Equal(t, action.ActionNone, s.Load()) | ||
|
||
s.Require(action.ActionReload) | ||
require.Equal(t, action.ActionReload, s.Load(), "overwrite") | ||
|
||
s.Require(action.ActionRestart) | ||
require.Equal(t, action.ActionRestart, s.Load(), "overwrite") | ||
|
||
s.Require(action.ActionReload) | ||
require.Equal(t, action.ActionRestart, s.Load(), "no overwrite") | ||
|
||
s.Require(action.ActionRebuild) | ||
require.Equal(t, action.ActionRebuild, s.Load(), "overwrite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.