go的类型()的作用

 1.23 KB
 
  package model
   
  import (
  "database/sql/driver"
  "encoding/json"
  "fmt"
  )
   
  type JsonArrayUint []uint
   
  func (o JsonArrayUint) Value() (driver.Value, error) {
  b, err := json.Marshal(o)
  return string(b), err
  }
   
  func (o *JsonArrayUint) Scan(input interface{}) (err error) {
   
  switch v := input.(type) {
  case []byte:
  return json.Unmarshal(v, o)
  case string:
  return json.Unmarshal([]byte(v), o)
  default:
  err = fmt.Errorf("unexpected type %T in JsonArrayUint", v)
  }
  return err
  }
  func (m JsonArrayUint) MarshalJSONArrayUint() ([]byte, error) {
  return json.Marshal(m)
  }
   
  func (m *JsonArrayUint) UnmarshalJSONArrayUint(data []byte) error {
  return json.Unmarshal(data, m)
  }
  func (j JsonArrayUint) IsNull() bool {
  return len(j) == 0
  }
   
  func (j JsonArrayUint) Equals(j1 JsonArrayUint) bool {
  t1 := []uint(j)
  t2 := []uint(j1)
  if len(t1) != len(t2) {
  return false
  }
  for k, vv := range t1 {
  if t2[k] != vv {
  return false
  }
  }
  return true
  }
   
  func (j JsonArrayUint) AppendOrRemove(e uint) (isExist bool, a JsonArrayUint) {
  temp := []uint{}
  for _, v := range j {
  if v == e {
  isExist = true
  continue
  }
  temp = append(temp, v)
  }
  //不存在 添加e
  if !isExist {
  temp = append(temp, e)
  }
  a = JsonArrayUint(temp)
  return isExist, a
  }
posted @   技术颜良  阅读(33)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
历史上的今天:
2021-05-15 ansible-playbook调试
2019-05-15 Java静态方法和实例方法区别详解
2018-05-15 docker:轻量级图形页面管理之Portainer
点击右上角即可分享
微信分享提示