https://github.com/cristaloleg/sabotage
Collection of dirty hacks in Go
https://github.com/cristaloleg/sabotage
golang monkey-patching unsafe
Last synced: about 1 year ago
JSON representation
Collection of dirty hacks in Go
- Host: GitHub
- URL: https://github.com/cristaloleg/sabotage
- Owner: cristaloleg
- License: bsd-3-clause
- Created: 2019-02-13T22:22:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-18T09:15:44.000Z (about 3 years ago)
- Last Synced: 2025-03-15T01:44:57.626Z (over 1 year ago)
- Topics: golang, monkey-patching, unsafe
- Language: Go
- Homepage:
- Size: 50.8 KB
- Stars: 67
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SABOTAGE
[](https://travis-ci.org/cristaloleg/sabotage)
[](https://godoc.org/github.com/cristaloleg/sabotage)
[](https://goreportcard.com/report/github.com/cristaloleg/sabotage)
Collection of dirty hacks in Go.
1. Repeat `sync.Once` once more.
2. Check if `sync.Mutex`/`sync.RWMutex` is locked.
3. `[]byte <-> string` conversion without additional allocation.

Cause what you see, you might not get
And we can bet, so don't you get souped yet
Scheming on a thing, that's a mirage
I'm trying to tell you now, it's sabotage
Whhhhhyyyyyy??????
(c) Beastie Boys - Sabotage
## Examples
1. You can repeat `sync.Once` as much as you want:
```go
var once sync.Once
once.Do(myFunc)
sabotage.ResetSyncOnce(&once)
```
or check if it was invoked earlier:
```go
if sabotage.IsOnceDone(&once) {
println("well-well-well")
}
```
2. You can unlock any mutex from anywhere:
```go
var mu sync.Mutex
// let's yolo begins
sabotage.UnlockMutex(&mu)
```
or check if it's locked:
```go
if sabotage.IsMutexLocked(&mu) {
for {
// let's wait a bit
}
}
```