Initial commit

This commit is contained in:
dushixiang
2020-12-20 21:19:11 +08:00
commit e7f2773c77
77 changed files with 27866 additions and 0 deletions

14
pkg/config/config.go Normal file
View File

@ -0,0 +1,14 @@
package config
import (
"github.com/patrickmn/go-cache"
"gorm.io/gorm"
)
var DB *gorm.DB
var Cache *cache.Cache
var NextTerminal *NextTerminalConfig
var Store *TunStore

View File

@ -0,0 +1,31 @@
package config
import (
"github.com/spf13/viper"
"log"
)
type NextTerminalConfig struct {
Dsn string
Addr string
}
func SetupConfig() *NextTerminalConfig {
viper.SetConfigName("next-terminal")
viper.SetConfigType("yaml")
viper.AddConfigPath("/etc/next-terminal/")
viper.AddConfigPath("$HOME/.next-terminal")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
log.Fatal(err)
}
var config = &NextTerminalConfig{
Dsn: viper.GetString("next-terminal.dsn"),
Addr: viper.GetString("next-terminal.addr"),
}
return config
}

37
pkg/config/store.go Normal file
View File

@ -0,0 +1,37 @@
package config
import (
"github.com/pkg/sftp"
"next-terminal/pkg/guacd"
"sync"
)
type Tun struct {
Tun guacd.Tunnel
SftpClient *sftp.Client
}
type TunStore struct {
m sync.Map
}
func (s *TunStore) Set(k string, v Tun) {
s.m.Store(k, v)
}
func (s *TunStore) Del(k string) {
s.m.Delete(k)
}
func (s *TunStore) Get(k string) (item Tun, ok bool) {
value, ok := s.m.Load(k)
if ok {
return value.(Tun), true
}
return item, false
}
func NewStore() *TunStore {
store := TunStore{sync.Map{}}
return &store
}