Files
wazero/internal/gojs/config/config.go
Takeshi Yoneda f24a3f49a4 gojs: refactors out gojs.Config type (#1240)
In order to support more configuration, we should stop using context as
it is getting gnarly.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-15 12:27:47 +08:00

43 lines
868 B
Go

// Package config exists to avoid dependency cycles when keeping most of gojs
// code internal.
package config
import (
"net/http"
"os"
"path/filepath"
"github.com/tetratelabs/wazero/internal/platform"
)
type Config struct {
OsWorkdir bool
Rt http.RoundTripper
// Workdir is the actual working directory value.
Workdir string
}
func NewConfig() *Config {
return &Config{Workdir: "/"}
}
func (c *Config) Clone() *Config {
ret := *c // copy except maps which share a ref
return &ret
}
func (c *Config) Init() error {
if c.OsWorkdir {
workdir, err := os.Getwd()
if err != nil {
return err
}
// Ensure if used on windows, the input path is translated to a POSIX one.
workdir = platform.ToPosixPath(workdir)
// Strip the volume of the path, for example C:\
c.Workdir = workdir[len(filepath.VolumeName(workdir)):]
}
return nil
}