// Copyright (c) 2021. Huawei Technologies Co., Ltd. All rights reserved.

// Package common this file for time format
package common

import (
"database/sql/driver"
"fmt"
"time"
)

const timeFormat = "2006-01-02 15:04:05"

// DateTime DateTime
type DateTime time.Time

// MarshalJSON for time format to datetime
func (t DateTime) MarshalJSON() ([]byte, error) {
datetime := fmt.Sprintf(`"%s"`, time.Time(t).Format(timeFormat))
return []byte(datetime), nil
}

// Value insert timestamp into mysql need this function.
func (t DateTime) Value() (driver.Value, error) {
var zeroTime time.Time
ti := time.Time(t)
if ti.UnixNano() == zeroTime.UnixNano() {
return nil, nil
}
return ti, nil
}

// Scan valueof time.Time
func (t *DateTime) Scan(v interface{}) error {
ti, ok := v.(time.Time) // NOT directly assertion v.(DateTime)
if ok {
*t = DateTime(ti)
return nil
}
return fmt.Errorf("can not convert %v to timestamp", v)
}

// ResultMsg resp struct
type ResultMsg struct {
Status string `json:"status"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}

// PageResult pagequery resut
type PageResult struct {
CurrentPage int `json:"currentPage"`
PageSize int `json:"pageSize"`
PageCount uint64 `json:"pageCount"`
Total uint64 `json:"total"`
Data interface{} `json:"data"`
}

const (
// StatusOK status
StatusOK = 200
// StatusFailed failed status
StatusFailed = 400
// BaseHex Base Parse integer need params
BaseHex = 10
// BitSize64 Base Parse integer need params
BitSize64 = 64

// HTTPServerTimeout http server timeout
HTTPServerTimeout = 20
// MaxConcurrency default max concurrency
MaxConcurrency = 100
// DefaultConcurrency default concurrency
DefaultConcurrency = 20
// SortByAsc sort by asc
SortByAsc = "asc"
// SortByDesc sort by desc
SortByDesc = "desc"
// MaxPageSize the max page size
MaxPageSize = 100
// ContentDisposition header information
ContentDisposition = "Content-Disposition"
// ContentType header information
ContentType = "Content-Type"
// AcceptLength header information
AcceptLength = "Accept-Length"

// ConnectionRetryTimes retry connect times
ConnectionRetryTimes = 3
// DefaultRequestTimeout internal request timeout
DefaultRequestTimeout = 5
)

// NewDateTime new DateTime for marshal
func NewDateTime(time2 time.Time) *DateTime {
if time2.IsZero() {
return nil
}

datetime := DateTime(time2)
return &datetime
}

mindxdl--common--type.go的更多相关文章

  1. c# Entity DbArithmeticExpression arguments must have a numeric common type

    在Entity Lambda表达式中计算DateTime类型的时候 不能直接用DateTime类型进行相减计算差值 需要使用DbFunctions提供的一些方法. 例如: DbFunctions.Di ...

  2. DbArithmeticExpression arguments must have a numeric common type.

    引用 system.data.linq

  3. 深入理解.net - 3.类型Type

    说到类型,.NET技术是基于通用类型系统(CTS,Common Type System)的,而CTS又是构建于公共语言架构(CLI,Common Language Infrastructure)之上, ...

  4. 深入理解C#

    简单认识.NET框架    (1)首先我们得知道 .NET框架具有两个主要组件:公共语言进行时CLR(Common Language Runtime)和框架类库FCL(Framework Class ...

  5. .NET平台和C#编程的总结

    第一章   简单认识.NET框架    (1)首先我们得知道 .NET框架具有两个主要组件:公共语言进行时CLR(Common Language Runtime)和框架类库FCL(Framework ...

  6. 深入.NET平台和C#编程总结大全

    对于初学者的你,等到你把这个看完之后就更清楚地认知.NET和C#编程了,好了废话不多说,开始吧!                                                     ...

  7. .NET面试题集锦①(Part一)

    一.前言部分 文中的问题及答案多收集整理自网络,不保证100%准确,还望斟酌采纳. 1.面向对象的思想主要包括什么? 答:任何事物都可以理解为对象,其主要特征: 继承.封装.多态.特点:代码好维护,安 ...

  8. .Net 面试题 3C(CTS,CLS,CLR)

    1.CTS(Common Type System)通用类型系统 CTS不但实现了COM的变量兼容类型,而且还定义了通过用户自定义类型的方式来进行类型扩展.任何以.NET平台作为目标的语言必须建立它的数 ...

  9. .net erp(办公oa)开发平台架构之流程服务概要介绍

    背景 搭建一个适合公司erp业务的开发平台. 架构概要图:    流程引擎开发平台:  包含流程引擎设计器,流程管理平台,流程引擎服务.目前只使用单个数据库进行管理.  流程引擎设计器 采用silve ...

  10. .net framework体系结构

    CIL(common intermediate language):公共中间语言..net框架下各种种类.版本的编程语言在经过编译后生成的中间语言(后缀为.il),与平台无关.与语言无关,只要机器上运 ...

随机推荐

  1. 使用 Mypy 检查 30 万行 Python 代码,总结出 3 大痛点与 6 个技巧!

    作者:Charlie Marsh 译者:豌豆花下猫@Python猫 英文:Using Mypy in production at Spring (https://notes.crmarsh.com/u ...

  2. mac_VMWare安装总结

    MacOS 安装VmWare 总结 如果之前安装过virtualBox,virtualBox的内核扩展会影响到VmWare的使用 *比如会导致VMWare虽然可以安装,却无法创建虚拟机 这是需要执行以 ...

  3. python 基于aiohttp的异步爬虫实战

    钢铁知识库,一个学习python爬虫.数据分析的知识库.人生苦短,快用python. 之前我们使用requests库爬取某个站点的时候,每发出一个请求,程序必须等待网站返回响应才能接着运行,而在整个爬 ...

  4. 坚守自主创新,璞华HawkEye IETM系统惠及国计民生

    可上九天揽月,可下五洋捉鳖,这是我们很多年的梦想.而要实现这样的梦想,不仅需要安全可靠的技术装备,还需要让这些技术装备处于良好的维保状态.于是,作为装备维保过程中必须的知识创作.管理.发布.浏览工具, ...

  5. 无线配置多一个路由器作为家庭wifi的无线热点?

    以下内容为本人的著作,如需要转载,请声明原文链接微信公众号「englyf」https://www.cnblogs.com/englyf/ 手头上有个 MERCURY 的破旧路由器,怎么配置它,让它作为 ...

  6. 发布日志 - kratos v2.1.0 版本发布

    github https://github.com/go-kratos/kratos/releases/tag/v2.1.0 新的功能 新增客户端负载均衡器(load balancing)和路由选择器 ...

  7. Promtail 配置文件说明

    转载自:https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247492163&idx=1&sn=56b26aa387 ...

  8. Kubernetes 监控:Prometheus Operator + Thanos ---实践篇

    具体参考网址:https://www.cnblogs.com/sanduzxcvbnm/p/16291296.html 本章用到的yaml文件地址:https://files.cnblogs.com/ ...

  9. kvm使用桥接的方法

    什么是桥接 桥接就是把物理机的网卡模拟成交换机,虚拟机的网卡直接连在虚拟的网桥即交换机上.这样kvm虚拟机分配的IP地址,就应该和物理机在同一网段,可以对外进行服务. 在KVM下运行的VM默认的网卡采 ...

  10. Ceph分布式存储详述

    存储发展史 企业中使用存储按照其功能,使用场景,一直在持续发展和迭代,大体上可以分为四个阶段: DAS:Direct Attached Storage,即直连存储,第一代存储系统,通过SCSI总线扩展 ...