pkg/environment: Remove 'net' related functions
This commit continues removing the environment abstraction and removes all 'net' related functions, replacing them by their native equivalents.
This commit is contained in:
parent
14bb7f1086
commit
39207a1cb5
7 changed files with 8 additions and 47 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
|
|
@ -64,7 +65,7 @@ func (s server) Run(context wisski_distillery.Context) error {
|
|||
publicC := make(chan error)
|
||||
{
|
||||
zerolog.Ctx(context.Context).Info().Str("bind", s.Bind).Msg("listening public server")
|
||||
publicL, err := dis.Still.Environment.Listen("tcp", s.Bind)
|
||||
publicL, err := net.Listen("tcp", s.Bind)
|
||||
if err != nil {
|
||||
return errServerListen.Wrap(err)
|
||||
}
|
||||
|
|
@ -79,7 +80,7 @@ func (s server) Run(context wisski_distillery.Context) error {
|
|||
internalC := make(chan error)
|
||||
{
|
||||
zerolog.Ctx(context.Context).Info().Str("bind", s.InternalBind).Msg("listening internal server")
|
||||
internalL, err := dis.Still.Environment.Listen("tcp", s.InternalBind)
|
||||
internalL, err := net.Listen("tcp", s.InternalBind)
|
||||
if err != nil {
|
||||
return errServerListen.Wrap(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
|
|
@ -39,7 +41,7 @@ func (s ssh) Run(context wisski_distillery.Context) error {
|
|||
context.Printf("Listening on %s\n", s.Bind)
|
||||
|
||||
// make a new listener
|
||||
listener, err := dis.Still.Environment.Listen("tcp", s.Bind)
|
||||
listener, err := net.Listen("tcp", s.Bind)
|
||||
if err != nil {
|
||||
return errServerListen.Wrap(err)
|
||||
}
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -6,7 +6,6 @@ require (
|
|||
github.com/FAU-CDI/wdresolve v0.0.0-20230108072141-c9c6779d7c41
|
||||
github.com/alessio/shellescape v1.4.1
|
||||
github.com/gliderlabs/ssh v0.3.5
|
||||
github.com/go-sql-driver/mysql v1.7.0
|
||||
github.com/gorilla/csrf v1.7.1
|
||||
github.com/gorilla/sessions v1.2.1
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
|
|
@ -32,6 +31,7 @@ require (
|
|||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
|
||||
github.com/boombuler/barcode v1.0.1 // indirect
|
||||
github.com/feiin/sqlstring v0.3.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||
github.com/gorilla/securecookie v1.1.1 // indirect
|
||||
github.com/gosuri/uilive v0.0.4 // indirect
|
||||
github.com/jessevdk/go-flags v1.5.0 // indirect
|
||||
|
|
|
|||
|
|
@ -4,12 +4,8 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
mysqldriver "github.com/go-sql-driver/mysql"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
|
|
@ -119,25 +115,8 @@ func (ssql *SQL) connect(database string) (*sql.DB, error) {
|
|||
func (sql *SQL) dsn(database string) string {
|
||||
user := sql.Config.SQL.AdminUsername
|
||||
pass := sql.Config.SQL.AdminPassword
|
||||
network := sql.network()
|
||||
network := "tcp"
|
||||
server := sql.ServerURL
|
||||
|
||||
return fmt.Sprintf("%s:%s@%s(%s)/%s?charset=utf8&parseTime=True&loc=Local", user, pass, network, server, database)
|
||||
}
|
||||
|
||||
var proxyNameCounter uint64
|
||||
|
||||
// network returns the network to use to connect to the database
|
||||
func (sql *SQL) network() string {
|
||||
return sql.lazyNetwork.Get(func() (name string) {
|
||||
network := "tcp"
|
||||
|
||||
// register a new DialContext function to use the environment.
|
||||
// this seems like a bit of a hack, but it works for now.
|
||||
name = fmt.Sprintf("sql-network-%d", atomic.AddUint64(&proxyNameCounter, 1))
|
||||
mysqldriver.RegisterDialContext(name, func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return sql.Still.Environment.DialContext(ctx, network, addr)
|
||||
})
|
||||
return
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ func (ts Triplestore) OpenRaw(ctx context.Context, method, url string, body any,
|
|||
// create the request object
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
DialContext: ts.Environment.DialContext,
|
||||
DisableKeepAlives: true,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
package environment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -38,9 +36,6 @@ type Environment interface {
|
|||
WalkDir(root string, fn fs.WalkDirFunc) error
|
||||
|
||||
Abs(path string) (string, error)
|
||||
|
||||
Listen(network, address string) (net.Listener, error)
|
||||
DialContext(context context.Context, network, address string) (net.Conn, error)
|
||||
}
|
||||
|
||||
type WritableFile interface {
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
package environment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
)
|
||||
|
||||
func (*Native) Listen(network, address string) (net.Listener, error) {
|
||||
return net.Listen(network, address)
|
||||
}
|
||||
|
||||
func (*Native) DialContext(context context.Context, network, address string) (net.Conn, error) {
|
||||
var d net.Dialer
|
||||
return d.DialContext(context, network, address)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue