|
1 |
| -/* |
2 |
| -MIT License |
3 |
| -
|
4 |
| -Copyright (c) 2022 r7wx |
5 |
| -
|
6 |
| -Permission is hereby granted, free of charge, to any person obtaining a copy |
7 |
| -of this software and associated documentation files (the "Software"), to deal |
8 |
| -in the Software without restriction, including without limitation the rights |
9 |
| -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 |
| -copies of the Software, and to permit persons to whom the Software is |
11 |
| -furnished to do so, subject to the following conditions: |
12 |
| -The above copyright notice and this permission notice shall be included in all |
13 |
| -copies or substantial portions of the Software. |
14 |
| -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 |
| -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 |
| -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17 |
| -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 |
| -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 |
| -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
20 |
| -SOFTWARE. |
21 |
| -*/ |
22 |
| - |
23 | 1 | package config
|
24 | 2 |
|
25 | 3 | import (
|
26 | 4 | "encoding/json"
|
| 5 | + "fmt" |
27 | 6 |
|
28 |
| - "github.com/r7wx/easy-gate/internal/errors" |
29 |
| - "github.com/r7wx/easy-gate/internal/models" |
| 7 | + "github.com/r7wx/easy-gate/internal/group" |
| 8 | + "github.com/r7wx/easy-gate/internal/theme" |
30 | 9 | "gopkg.in/yaml.v3"
|
31 | 10 | )
|
32 | 11 |
|
33 | 12 | // Service - Easy Gate service configuration struct
|
34 | 13 | type Service struct {
|
35 |
| - Icon string `json:"icon" yaml:"icon"` |
36 |
| - Name string `json:"name" yaml:"name"` |
37 |
| - URL string `json:"url" yaml:"url"` |
38 |
| - Groups []string `json:"groups" yaml:"groups"` |
| 14 | + Icon string `json:"icon" yaml:"icon"` |
| 15 | + Name string `json:"name" yaml:"name"` |
| 16 | + URL string `json:"url" yaml:"url"` |
| 17 | + Category string `json:"category" yaml:"category"` |
| 18 | + Groups []string `json:"groups" yaml:"groups"` |
39 | 19 | }
|
40 | 20 |
|
41 | 21 | // Note - Easy Gate note configuration struct
|
42 | 22 | type Note struct {
|
43 |
| - Name string `json:"name" yaml:"name"` |
44 |
| - Text string `json:"text" yaml:"text"` |
45 |
| - Groups []string `json:"groups" yaml:"groups"` |
| 23 | + Name string `json:"name" yaml:"name"` |
| 24 | + Text string `json:"text" yaml:"text"` |
| 25 | + Category string `json:"category" yaml:"category"` |
| 26 | + Groups []string `json:"groups" yaml:"groups"` |
46 | 27 | }
|
47 | 28 |
|
48 | 29 | // Config - Easy Gate configuration struct
|
49 | 30 | type Config struct {
|
50 |
| - Theme models.Theme `json:"theme" yaml:"theme"` |
51 |
| - Addr string `json:"addr" yaml:"addr"` |
52 |
| - Title string `json:"title" yaml:"title"` |
53 |
| - CertFile string `json:"cert_file" yaml:"cert_file"` |
54 |
| - KeyFile string `json:"key_file" yaml:"key_file"` |
55 |
| - Groups []models.Group `json:"groups" yaml:"groups"` |
56 |
| - Services []Service `json:"services" yaml:"services"` |
57 |
| - Notes []Note `json:"notes" yaml:"notes"` |
58 |
| - BehindProxy bool `json:"behind_proxy" yaml:"behind_proxy"` |
59 |
| - UseTLS bool `json:"use_tls" yaml:"use_tls"` |
| 31 | + Theme theme.Theme `json:"theme" yaml:"theme"` |
| 32 | + Addr string `json:"addr" yaml:"addr"` |
| 33 | + Title string `json:"title" yaml:"title"` |
| 34 | + CertFile string `json:"cert_file" yaml:"cert_file"` |
| 35 | + KeyFile string `json:"key_file" yaml:"key_file"` |
| 36 | + Groups []group.Group `json:"groups" yaml:"groups"` |
| 37 | + Services []Service `json:"services" yaml:"services"` |
| 38 | + Notes []Note `json:"notes" yaml:"notes"` |
| 39 | + BehindProxy bool `json:"behind_proxy" yaml:"behind_proxy"` |
| 40 | + UseTLS bool `json:"use_tls" yaml:"use_tls"` |
60 | 41 | }
|
61 | 42 |
|
62 | 43 | type format int
|
@@ -86,8 +67,5 @@ func Unmarshal(configBytes []byte) (*Config, error) {
|
86 | 67 | }
|
87 | 68 | }
|
88 | 69 |
|
89 |
| - return nil, errors.NewEasyGateError( |
90 |
| - errors.InvalidFormat, |
91 |
| - errors.ConfigurationFile, "", |
92 |
| - ) |
| 70 | + return nil, fmt.Errorf("Invalid configuration file format") |
93 | 71 | }
|
0 commit comments