MCPcopy Create free account
hub / github.com/kataras/iris / LoadOptions

Function LoadOptions

middleware/rewrite/rewrite.go:38–64  ·  view source on GitHub ↗

LoadOptions loads rewrite Options from a system file.

(filename string)

Source from the content-addressed store, hash-verified

36
37// LoadOptions loads rewrite Options from a system file.
38func LoadOptions(filename string) (opts Options) {
39 ext := ".yml"
40 if index := strings.LastIndexByte(filename, '.'); index > 1 && len(filename)-1 > index {
41 ext = filename[index:]
42 }
43
44 f, err := os.Open(filename)
45 if err != nil {
46 panic("iris: rewrite: " + err.Error())
47 }
48 defer f.Close()
49
50 switch ext {
51 case ".yaml", ".yml":
52 err = yaml.NewDecoder(f).Decode(&opts)
53 case ".json":
54 err = json.NewDecoder(f).Decode(&opts)
55 default:
56 panic("iris: rewrite: unexpected file extension: " + filename)
57 }
58
59 if err != nil {
60 panic("iris: rewrite: decode: " + err.Error())
61 }
62
63 return
64}
65
66// Rewrite is a struct that represents a rewrite engine for Iris web framework.
67// It contains a slice of redirect rules, an options struct, a logger, and a domain validator function.

Callers 1

LoadFunction · 0.85

Calls 4

ErrorMethod · 0.65
CloseMethod · 0.65
DecodeMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…