Created
July 2, 2025 15:10
-
-
Save Kabilan108/1239f602361a50560a1cc91ec7ca1bb4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // https://github.com/ThePrimeagen/vim-with-me/blob/ed0c65594a6a0f5f98f8fbb69c5c44633846ec70/pkg/assert/assert.go | |
| package assert | |
| import ( | |
| "log" | |
| "log/slog" | |
| ) | |
| var assertData map[string]any = map[string]any{} | |
| func AddAssertData(key string, value any) { | |
| assertData[key] = value | |
| } | |
| func RemoveAssertData(key string) { | |
| delete(assertData, key) | |
| } | |
| func runAssert(msg string) { | |
| for k, v := range assertData { | |
| slog.Error("context", "key", k, "value", v) | |
| } | |
| log.Fatal(msg) | |
| } | |
| // TODO: Think about passing around a context for debugging purposes | |
| func Assert(truth bool, msg string) { | |
| if !truth { | |
| runAssert(msg) | |
| } | |
| } | |
| func NoError(err error, msg string) { | |
| if err != nil { | |
| slog.Error("NoError#error encountered", "error", err) | |
| runAssert(msg) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment