Validate checks whether Configuration represent a valid configuration
()
| 42 | |
| 43 | // Validate checks whether Configuration represent a valid configuration |
| 44 | func (o Configuration) Validate() error { |
| 45 | if o.PackageName == "" { |
| 46 | return errors.New("package name must be specified") |
| 47 | } |
| 48 | |
| 49 | // Only one server type should be specified at a time. |
| 50 | nServers := 0 |
| 51 | if o.Generate.IrisServer { |
| 52 | nServers++ |
| 53 | } |
| 54 | if o.Generate.ChiServer { |
| 55 | nServers++ |
| 56 | } |
| 57 | if o.Generate.FiberServer { |
| 58 | nServers++ |
| 59 | } |
| 60 | if o.Generate.EchoServer { |
| 61 | nServers++ |
| 62 | } |
| 63 | if o.Generate.Echo5Server { |
| 64 | nServers++ |
| 65 | } |
| 66 | if o.Generate.GorillaServer { |
| 67 | nServers++ |
| 68 | } |
| 69 | if o.Generate.StdHTTPServer { |
| 70 | nServers++ |
| 71 | } |
| 72 | if o.Generate.GinServer { |
| 73 | nServers++ |
| 74 | } |
| 75 | if nServers > 1 { |
| 76 | return errors.New("only one server type is supported at a time") |
| 77 | } |
| 78 | |
| 79 | var errs []error |
| 80 | if problems := o.Generate.Validate(); problems != nil { |
| 81 | for k, v := range problems { |
| 82 | errs = append(errs, fmt.Errorf("`generate` configuration for %v was incorrect: %v", k, v)) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if problems := o.Compatibility.Validate(); problems != nil { |
| 87 | for k, v := range problems { |
| 88 | errs = append(errs, fmt.Errorf("`compatibility-options` configuration for %v was incorrect: %v", k, v)) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if problems := o.OutputOptions.Validate(); problems != nil { |
| 93 | for k, v := range problems { |
| 94 | errs = append(errs, fmt.Errorf("`output-options` configuration for %v was incorrect: %v", k, v)) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | err := errors.Join(errs...) |
| 99 | if err != nil { |
| 100 | return fmt.Errorf("failed to validate configuration: %w", err) |
| 101 | } |
no outgoing calls
no test coverage detected