go database/sql/driver driver.Value的作用

import (
"database/sql/driver"
"encoding/json"
"github.com/sirupsen/logrus"
"sshfortress/util"
)

type HardwareInfo struct {
Disk string `json:"hi_disk"`
Mem string `json:"hi_mem"`
NetCard string `json:"hi_net_card"`
Cpu string `json:"hi_cpu"`
System string `json:"hi_system"`
Login string `json:"hi_login"`
Ps string `json:"hi_ps"`
Port string `json:"hi_port"`
}

func (o HardwareInfo) Value() (driver.Value, error) {
b, err := json.Marshal(o)
return string(b), err
}

func (o *HardwareInfo) Scan(input interface{}) error {
return json.Unmarshal(input.([]byte), o)
}
posted @ 2022-04-07 09:31  技术颜良  阅读(143)  评论(0编辑  收藏  举报