11
22import Foundation
3-
4- /// This struct represents the configuration of
5- /// an application
6- /// example usage:
7- /// // path represents a json file location that have the same key names as the struct props
8- /// let file = File(path)
9- /// if file.exists == false {
10- /// print("Configuration file doesn't exist!")
11- /// }
12- /// do {
13- /// try file.open(.read, permissions: .readUser)
14- /// defer { file.close() }
15- /// let json = try file.readString()
16- /// let conf = try Configuration(json)
17- /// app.config = conf // assign it to your application's config to be used when you launch the server
18- /// } catch {
19- /// print(error)
20- /// }
21-
3+ /**
4+ This struct represents the configuration of an application
5+ ### Example usage: ###
6+ ````
7+ // path represents a json file location that have the same key names as the struct props
8+ let file = File(path)
9+ if file.exists == false {
10+ print("Configuration file doesn't exist!")
11+ }
12+ do {
13+ try file.open(.read, permissions: .readUser)
14+ defer { file.close() }
15+ let json = try file.readString()
16+ let conf = try Configuration(json)
17+ app.config = conf // assign it to your application's config to be used when you launch the server
18+ } catch {
19+ print(error)
20+ }
21+ ````
22+ */
2223public struct Configuration : Codable {
2324 /// server configuration including url and port
2425 let server : ServerConfiguration ?
@@ -35,31 +36,59 @@ public struct Configuration: Codable {
3536 let environment : Environment ?
3637}
3738
38- /// This struct represents the server configuration
39+ /**
40+ This struct represents the server configuration
41+ */
3942public struct ServerConfiguration : Codable {
43+ /// base URL
4044 let baseURL : String ?
45+ /// base domain
4146 let baseDomain : String ?
47+ /// port
4248 let port : Int ?
49+ /// if it is a https server 1 else 0
4350 let secure : Int ?
4451}
4552
46- /// configuration for logging
53+ /**
54+ configuration for logging
55+ */
4756public struct LoggingConfiguration : Codable {
57+ /// logging path for requests
4858 let requestLoggingPath : String ?
59+ /// logging path
4960 let logPath : String ?
5061}
5162
52- /// database configuration that should be initialized when Configuration is initialized
53- /// ScantORM uses this configuration to initialize the DatabaseAdapter
54- /// You can use it without ScantORM if you need to
63+ /**
64+ database configuration that should be initialized when Configuration is initialized.
65+ **ScantORM** uses this configuration to initialize the DatabaseAdapter.
66+ You can use it without ScantORM if you need to!
67+ */
5568public struct DBConfiguration : Codable {
69+ /// database name
5670 public let name : String ?
71+ /// host url
5772 public let host : String ?
73+ /// port
5874 public let port : Int ?
75+ /// database user name
5976 public let user : String ?
77+ /// database password
6078 public let pass : String ?
79+ /// database driver type
6180 public let driverType : DBDriverType
6281
82+ /**
83+ initialize the database configuration
84+ - parameters:
85+ - name: database name
86+ - host: host url
87+ - port: port address
88+ - user: user name
89+ - pass: password
90+ - driverType: database driver type such as mySQL
91+ */
6392 public init ( name: String ? ,
6493 host: String ? ,
6594 port: Int ? ,
@@ -75,36 +104,57 @@ public struct DBConfiguration: Codable {
75104 }
76105}
77106
78- /// Database driver type
107+ /**
108+ Database driver type
109+ */
79110public enum DBDriverType : Int , Codable {
111+ /// MySQL
80112 case mySQL = 1
113+ /// PostgreSQL
81114 case postgreSQL = 2
115+ /// SQLite
82116 case sqLite = 3
83117}
84118
85- /// SSL configuration for https server
119+ /**
120+ SSL configuration for https server
121+ */
86122public struct SSLConfiguration : Codable {
123+ /// https port
87124 let port : Int ?
125+ /// origin certificate path
88126 let originCertificatePath : String ?
127+ /// private key path
89128 let privateKeyPath : String ?
129+ /// verify mode
90130 let verifyMode : String ?
91131}
92132
93- /// operating system
133+ /**
134+ operating system
135+ */
94136public enum OS : Int , Codable {
137+ /// Linux
95138 case linux = 1
139+ /// macOS
96140 case macOS = 2
97141}
98142
99- /// deployment environment
143+ /**
144+ deployment environment
145+ */
100146public enum Environment : Int , Codable {
147+ /// development environment
101148 case dev = 1
149+ /// pre production environment
102150 case preProd = 2
151+ /// production environment
103152 case prod = 3
104153}
105154
106155// MARK: Convenience initializers
107156
157+
108158extension Configuration {
109159 /// init configuration with Data
110160 public init ( data: Data ) throws {
0 commit comments