RawConfig and MiningProfile had description-style comments restating what the types are rather than showing how to use them (AX Principle 2 violation). Replaced with concrete call-site examples demonstrating real usage patterns. Co-Authored-By: Charon <charon@lethean.io>
32 lines
959 B
Go
32 lines
959 B
Go
package mining
|
|
|
|
|
|
// var raw RawConfig
|
|
// _ = json.Unmarshal([]byte(`{"pool":"pool.lthn.io:3333"}`), &raw)
|
|
type RawConfig []byte
|
|
|
|
// profile := MiningProfile{ID: "abc", Name: "LTHN RandomX", MinerType: "xmrig", Config: raw}
|
|
// manager.SaveProfile(profile)
|
|
type MiningProfile struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
MinerType string `json:"minerType"` // e.g., "xmrig", "ttminer"
|
|
Config RawConfig `json:"config" swaggertype:"object"` // The raw JSON config for the specific miner
|
|
}
|
|
|
|
// data, err := profile.Config.MarshalJSON()
|
|
func (m RawConfig) MarshalJSON() ([]byte, error) {
|
|
if m == nil {
|
|
return []byte("null"), nil
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// if err := json.Unmarshal(raw, &profile.Config); err != nil { ... }
|
|
func (m *RawConfig) UnmarshalJSON(data []byte) error {
|
|
if m == nil {
|
|
return ErrInternal("RawConfig: UnmarshalJSON on nil pointer")
|
|
}
|
|
*m = append((*m)[0:0], data...)
|
|
return nil
|
|
}
|