go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/errutil/class.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package errutil 9 10 import "encoding/json" 11 12 // Class is a string wrapper that implements `error`. 13 // Use this to implement constant exception causes. 14 type Class string 15 16 // Class implements `error`. 17 func (c Class) Error() string { 18 return string(c) 19 } 20 21 // MarshalJSON implements json.Marshaler. 22 func (c Class) MarshalJSON() ([]byte, error) { 23 return json.Marshal(string(c)) 24 }