vurixwebapiclient

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 14 Imported by: 0

README

vurix-webapi-client

Innodep Vurix Webapi Client

Golang을 이용한 이노뎁(주)사의 WebAPI 클라이언트를 구현함

현재 처리된 내용

1. 로그인
2. KeepAlive (세션유지)
3. 이벤트 수신

사용예

	opt := NewOptVurixWebApiClient()
	opt.Host = "172.16.31.202"
	opt.Port = 8080
	opt.User = "admin"
	opt.Pass = "admin"
	opt.License = "licNormalClient"

	vc := NewVurixWebApiClient(opt)
	vc.Login()   // 로그인
	vc.Logout()  // 로그아웃

로그인이 완료되면 기본적으로 KeepAlive는 자동으로 처리된다

외부 logger 사용

	opt := NewOptVurixWebApiClient()
	opt.Host = "172.16.31.202"
	opt.Port = 8080
	opt.User = "admin"
	opt.Pass = "admin"
	opt.License = "licNormalClient"

	vc := NewVurixWebApiClient(opt)

	logger, _ := zap.NewDevelopment()   // Uber 로거를 만들어서 붙임
	vc.SetLogger(logger.Sugar())        // logger
	vc.SetDebug(true)                   // HTTP호출 상세로그를 기록하도록, 설정하는 플래그
	vc.Login()   // 로그인

	vc.Logout()  // 로그아웃

이벤트 수신

	opt := NewOptVurixWebApiClient()
	opt.Host = "172.16.31.202"
	opt.Port = 8080
	opt.User = "admin"
	opt.Pass = "admin"
	opt.License = "licNormalClient"

	vc := NewVurixWebApiClient(opt)
	vc.Login()

	// 이벤트를 붙이는 작업을 해야 한다.
	optVER := OptVurixEventReceiver{
		DeviceEvent:     true,
		MonitoringEvent: true,
		SystemEvent:     true,
		UserEvent:       true,
	}
	// 콜백함수와 함께 이벤트 옵션을 추가
	vc.SetEventHandler(CallbackFunc, optVER)

// 수신받을 Callback 함수를 선언
func CallbackFunc(msg interface{}) {
	jsonmsg, _ := json.Marshal(msg)
	fmt.Println("recv : ", time.Now(), string(jsonmsg))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventCallbackFunc

type EventCallbackFunc func(interface{})

type Logger

type Logger interface {
	Infof(format string, v ...interface{})
	Info(v ...interface{})
	Errorf(format string, v ...interface{})
	Error(v ...interface{})
	Warnf(format string, v ...interface{})
	Warn(v ...interface{})
	Debugf(format string, v ...interface{})
	Debug(v ...interface{})
}

type LoginInfo

type LoginInfo struct {
	AuthToken  string
	ApiSerial  int
	VmsID      int
	GrpSerial  int
	UserSerial int
	UserID     string
	UserName   string
	Utc        bool
}

type MultiPartParser

type MultiPartParser struct {
	// contains filtered or unexported fields
}

func NewMultiPartParser

func NewMultiPartParser() *MultiPartParser

func (*MultiPartParser) Parse

func (mp *MultiPartParser) Parse(data []byte, size int) (msg []byte, err error)

type OptVurixEventReceiver

type OptVurixEventReceiver struct {
	DeviceEvent      bool // event
	SystemEvent      bool // system
	MonitoringEvent  bool // monitoring
	UserLogEvent     bool // userlog
	UserEvent        bool // user
	VfsEvent         bool // vfs
	MasEvent         bool // mas
	EventPeriodByDev int  // 장비 이벤트(DEVICE_EVENT) 수신 시 장비별 수신주기 값(초)
}

type OptVurixWebApiClient

type OptVurixWebApiClient struct {
	Host    string
	Port    int
	User    string
	Pass    string
	Group   string
	License string
}

func NewOptVurixWebApiClient

func NewOptVurixWebApiClient() OptVurixWebApiClient

type VurixEventReceiver

type VurixEventReceiver struct {
	// contains filtered or unexported fields
}

func NewVurixEventReceiver

func NewVurixEventReceiver(option OptVurixEventReceiver) *VurixEventReceiver

func (*VurixEventReceiver) Run

func (ver *VurixEventReceiver) Run(logger Logger)

func (*VurixEventReceiver) SendMessage

func (ver *VurixEventReceiver) SendMessage(msg []byte)

func (*VurixEventReceiver) SetVurixWebApiClient

func (ver *VurixEventReceiver) SetVurixWebApiClient(vc *VurixWebApiClient)

func (*VurixEventReceiver) Stop

func (ver *VurixEventReceiver) Stop()

type VurixWebApiClient

type VurixWebApiClient struct {
	// contains filtered or unexported fields
}

func NewVurixWebApiClient

func NewVurixWebApiClient(opt OptVurixWebApiClient) *VurixWebApiClient

func (*VurixWebApiClient) GetDebug added in v0.1.2

func (vc *VurixWebApiClient) GetDebug() bool

func (*VurixWebApiClient) GetToken

func (vc *VurixWebApiClient) GetToken() (token string, apiserial int)

func (*VurixWebApiClient) KeepAlive

func (vc *VurixWebApiClient) KeepAlive() bool

http://host:port/api/keep-alive keep Alive에 실패할 경우, 로그인이 튕긴것이므로 다시 로그인이 되도록 처리한다

func (*VurixWebApiClient) Login

func (vc *VurixWebApiClient) Login()

func (*VurixWebApiClient) Logout

func (vc *VurixWebApiClient) Logout()

http://host:port/api/logout

func (*VurixWebApiClient) SetDebug

func (vc *VurixWebApiClient) SetDebug(debug bool)

func (*VurixWebApiClient) SetEventHandler

func (vc *VurixWebApiClient) SetEventHandler(callback EventCallbackFunc, opt OptVurixEventReceiver)

func (*VurixWebApiClient) SetLogger

func (vc *VurixWebApiClient) SetLogger(logger Logger)

func (*VurixWebApiClient) SleepWithContext

func (vc *VurixWebApiClient) SleepWithContext(d time.Duration)

Jump to

Keyboard shortcuts

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