-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement custom noroute html response
PR for #56
- Loading branch information
1 parent
693296b
commit a221ea2
Showing
10 changed files
with
118 additions
and
12 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
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
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,44 @@ | ||
package route | ||
|
||
import ( | ||
"log" | ||
"sync" | ||
"sync/atomic" | ||
) | ||
|
||
// HTML Wrapper struct so we can store the html string in an atomic.Value | ||
type HTML struct { | ||
value string | ||
} | ||
|
||
// html stores the no route html string | ||
var store atomic.Value | ||
|
||
func init() { | ||
store.Store(HTML{""}) | ||
} | ||
|
||
// GetHTML returns the HTML for not found routes. The function is safe to be | ||
// called from multiple goroutines. | ||
func GetHTML() string { | ||
return store.Load().(HTML).value | ||
} | ||
|
||
// hmu guards the atomic writes in SetHTML. | ||
var hmu sync.Mutex | ||
|
||
// SetHTML sets the current noroute html. The function is safe to be called from | ||
// multiple goroutines. | ||
func SetHTML(h string) { | ||
hmu.Lock() | ||
defer hmu.Unlock() | ||
|
||
html := HTML{h} | ||
store.Store(html) | ||
|
||
if h == "" { | ||
log.Print("[INFO] Unset noroute HTML") | ||
} else { | ||
log.Printf("[INFO] Set noroute HTML (%d bytes)", len(h)) | ||
} | ||
} |