zrok/http/http.go

36 lines
791 B
Go
Raw Normal View History

2022-07-20 19:18:40 +02:00
package http
import (
2022-07-21 22:01:39 +02:00
"github.com/openziti-test-kitchen/zrok/util"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/config"
"github.com/pkg/errors"
"net/http"
"time"
)
2022-07-20 19:18:40 +02:00
func Run(cfg *Config) error {
options := ziti.ListenOptions{
ConnectTimeout: 5 * time.Minute,
MaxConnections: 64,
}
zcfg, err := config.NewFromFile(cfg.IdentityPath)
if err != nil {
return errors.Wrap(err, "error loading config")
}
2022-07-26 22:00:59 +02:00
listener, err := ziti.NewContextWithConfig(zcfg).ListenWithOptions(cfg.Service, &options)
if err != nil {
return errors.Wrap(err, "error listening")
}
2022-07-26 22:00:59 +02:00
proxy, err := util.NewProxy(cfg.EndpointAddress)
2022-07-21 21:46:14 +02:00
if err != nil {
2022-07-21 22:01:39 +02:00
return err
}
2022-07-21 22:01:39 +02:00
if err := http.Serve(listener, util.NewProxyHandler(proxy)); err != nil {
2022-07-21 21:46:14 +02:00
return err
}
2022-07-20 21:25:34 +02:00
2022-07-21 21:46:14 +02:00
return nil
}