console.go 536 字节
Newer Older
Y
Your Name 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
package console

import (
	"context"
	"sync"
)

//Console console
type Console struct {
	adminHost   string
	port        int
	ctx         context.Context
	cancel      context.CancelFunc
	lastVersion int
	once        sync.Once
}

//Close close
func (c *Console) Close() {
	c.once.Do(c.cancel)
}

//NewConsole newConsole
func NewConsole(port int, adminHost string) *Console {
	ctx, cancel := context.WithCancel(context.Background())
	return &Console{
		port:      port,
		adminHost: adminHost,
		ctx:       ctx,
		cancel:    cancel,
	}
}