Mining/pkg/mining/mining_profile.go
Claude 565dae709d
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run
ax(mining): replace banned errors import with ErrInternal in mining_profile.go
RawConfig.UnmarshalJSON used errors.New() (banned import) despite the
package already providing ErrInternal() for exactly this purpose.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 08:42:39 +01:00

33 lines
1.1 KiB
Go

package mining
// RawConfig is a raw encoded JSON value.
// It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding.
// We define it as []byte (like json.RawMessage) to avoid swagger parsing issues with the json package.
type RawConfig []byte
// MiningProfile represents a saved configuration for running a specific miner.
// It decouples the UI from the underlying miner's specific config structure.
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
}