host

package
v0.0.0-...-8fd2309 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2022 License: MIT Imports: 7 Imported by: 3

README

Host 服务模块

IMPL

这个模块写完后, Host Service 的具体实现, 上层业务就基于Service进行编程, 面向接口

http
 |
Host Service (interface impl)
 |
impl(基于MySQL实现)

Host Service定义 并把实现编写完成, 使用方式有多种用途:

  • 用于内部模块调用, 基于他封装更高一层的业务逻辑, 比如发布服务
  • Host Service对外暴露: http协议(暴露给用户)
  • Host Service对外暴露: Grpc(暴露给内部服务)
  • ...

Documentation

Index

Constants

View Source
const (
	AppName = "host"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteHostRequest

type DeleteHostRequest struct {
	Id string
}

type Describe

type Describe struct {
	CPU          int    `json:"cpu" validate:"required"`    // 核数
	Memory       int    `json:"memory" validate:"required"` // 内存
	GPUAmount    int    `json:"gpu_amount"`                 // GPU数量
	GPUSpec      string `json:"gpu_spec"`                   // GPU类型
	OSType       string `json:"os_type"`                    // 操作系统类型,分为Windows和Linux
	OSName       string `json:"os_name"`                    // 操作系统名称
	SerialNumber string `json:"serial_number"`              // 序列号
}

type DescribeHostRequest

type DescribeHostRequest struct {
	Id string
}

func NewDescribeHostRequestWithId

func NewDescribeHostRequestWithId(id string) *DescribeHostRequest

type Host

type Host struct {
	// 资源公共属性部分
	*Resource
	// 资源独有属性部分
	*Describe
}

Host模型的定义

func NewHost

func NewHost() *Host

func (*Host) InjectDefault

func (h *Host) InjectDefault()

func (*Host) Patch

func (h *Host) Patch(obj *Host) error

对象的局部更新

func (*Host) Put

func (h *Host) Put(obj *Host) error

对象全量更新

func (*Host) Validate

func (h *Host) Validate() error

type HostSet

type HostSet struct {
	Total int     `json:"total"`
	Items []*Host `json:"items"`
}

func NewHostSet

func NewHostSet() *HostSet

func (*HostSet) Add

func (s *HostSet) Add(item *Host)

type QueryHostRequest

type QueryHostRequest struct {
	PageSize   int    `json:"page_size"`
	PageNumber int    `json:"page_number"`
	Keywords   string `json:"kws"`
}

func NewQueryHostFromHTTP

func NewQueryHostFromHTTP(r *http.Request) *QueryHostRequest

func NewQueryHostRequest

func NewQueryHostRequest() *QueryHostRequest

func (*QueryHostRequest) GetPageSize

func (req *QueryHostRequest) GetPageSize() uint

func (*QueryHostRequest) OffSet

func (req *QueryHostRequest) OffSet() int64

type Resource

type Resource struct {
	Id          string            `json:"id"  validate:"required"`     // 全局唯一Id
	Vendor      Vendor            `json:"vendor"`                      // 厂商
	Region      string            `json:"region"  validate:"required"` // 地域
	CreateAt    int64             `json:"create_at"`                   // 创建时间
	ExpireAt    int64             `json:"expire_at"`                   // 过期时间
	Type        string            `json:"type"  validate:"required"`   // 规格
	Name        string            `json:"name"  validate:"required"`   // 名称
	Description string            `json:"description"`                 // 描述
	Status      string            `json:"status"`                      // 服务商中的状态
	Tags        map[string]string `json:"tags"`                        // 标签
	UpdateAt    int64             `json:"update_at"`                   // 更新时间
	SyncAt      int64             `json:"sync_at"`                     // 同步时间
	Account     string            `json:"accout"`                      // 资源的所属账号
	PublicIP    string            `json:"public_ip"`                   // 公网IP
	PrivateIP   string            `json:"private_ip"`                  // 内网IP
}

type Service

type Service interface {
	// 录入主机
	CreateHost(context.Context, *Host) (*Host, error)
	// 查询主机列表
	QueryHost(context.Context, *QueryHostRequest) (*HostSet, error)
	// 查询主机详情
	DescribeHost(context.Context, *DescribeHostRequest) (*Host, error)
	// 主机更新
	UpdateHost(context.Context, *UpdateHostRequest) (*Host, error)
	// 主机删除, 比如前端需要 打印当前删除主机的Ip或者其他信息
	DeleteHost(context.Context, *DeleteHostRequest) (*Host, error)
}

host app service 的接口定义

type UPDATE_MODE

type UPDATE_MODE string
const (
	// 全量更新
	UPDATE_MODE_PUT UPDATE_MODE = "put"
	// 局部更新
	UPDATE_MODE_PATCH UPDATE_MODE = "patch"
)

type UpdateHostRequest

type UpdateHostRequest struct {
	UpdateMode UPDATE_MODE `json:"update_mode"`
	*Host
}

func NewPatchUpdateHostRequest

func NewPatchUpdateHostRequest(id string) *UpdateHostRequest

func NewPutUpdateHostRequest

func NewPutUpdateHostRequest(id string) *UpdateHostRequest

type Vendor

type Vendor int
const (
	// 枚举的默认值
	PRIVATE_IDC Vendor = iota
	// 阿里云
	ALIYUN
	// 腾讯云
	TXYUN
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL