Initial commit
This commit is contained in:
14
pkg/config/config.go
Normal file
14
pkg/config/config.go
Normal 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
|
31
pkg/config/next-terminal.go
Normal file
31
pkg/config/next-terminal.go
Normal 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
37
pkg/config/store.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user