mirror of
https://github.com/openziti/zrok.git
synced 2024-11-25 09:33:43 +01:00
28 lines
719 B
Go
28 lines
719 B
Go
package proxy
|
|
|
|
import (
|
|
"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"
|
|
)
|
|
|
|
func Run(cfg *Config) error {
|
|
zCfg, err := config.NewFromFile(cfg.IdentityPath)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error loading config")
|
|
}
|
|
zCtx := ziti.NewContextWithConfig(zCfg)
|
|
zDialCtx := util.ZitiDialContext{Context: zCtx}
|
|
zTransport := http.DefaultTransport.(*http.Transport).Clone()
|
|
zTransport.DialContext = zDialCtx.Dial
|
|
|
|
proxy, err := util.NewProxy("http://zrok")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
proxy.Transport = zTransport
|
|
return http.ListenAndServe(cfg.Address, util.NewProxyHandler(proxy))
|
|
}
|