31 lines
1 KiB
Go
31 lines
1 KiB
Go
package mining
|
|
|
|
// var rawConfig RawConfig
|
|
// _ = json.Unmarshal([]byte(`{"pool":"pool.lthn.io:3333"}`), &rawConfig)
|
|
type RawConfig []byte
|
|
|
|
// profile := MiningProfile{ID: "abc", Name: "LTHN RandomX", MinerType: "xmrig", Config: rawConfig}
|
|
// manager.SaveProfile(profile)
|
|
type MiningProfile struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
MinerType string `json:"minerType"` // Miner type such as `xmrig` or `ttminer`.
|
|
Config RawConfig `json:"config" swaggertype:"object"` // Raw JSON config for the selected miner profile.
|
|
}
|
|
|
|
// data, err := profile.Config.MarshalJSON() // returns the config blob unchanged.
|
|
func (m RawConfig) MarshalJSON() ([]byte, error) {
|
|
if m == nil {
|
|
return []byte("null"), nil
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// if err := json.Unmarshal(rawConfig, &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
|
|
}
|