mirror of https://github.com/vapor/docs.git
comments
This commit is contained in:
parent
c05546e41e
commit
7b4cd4f5b7
|
|
@ -27,7 +27,7 @@ And an example of how this might look:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
What that's saying, is that our application should start a single server named 'default' serving port `8080` on host `0.0.0.0`. This represents the following url: `http://localhost:8080`.
|
What that's saying, is that our application should start a single server named 'http' serving port `8080` on host `0.0.0.0`. This represents the following url: `http://localhost:8080`.
|
||||||
|
|
||||||
### Custom Keys
|
### Custom Keys
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ Let's add a custom key to the `servers.json` file:
|
||||||
|
|
||||||
This can be accessed from your application's config using the following.
|
This can be accessed from your application's config using the following.
|
||||||
|
|
||||||
```Swift
|
```swift
|
||||||
let customValue = app.config["server", "http", "custom-key"].string
|
let customValue = app.config["server", "http", "custom-key"].string
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -70,13 +70,13 @@ You can access your config directory with the following syntax. `app.config[<#fi
|
||||||
|
|
||||||
We can access this file by making sure the first argument in our subscript is keys. To get the first name in our list:
|
We can access this file by making sure the first argument in our subscript is keys. To get the first name in our list:
|
||||||
|
|
||||||
```Swift
|
```swift
|
||||||
let name = app.config["keys", "test-names", 0].string
|
let name = app.config["keys", "test-names", 0].string
|
||||||
```
|
```
|
||||||
|
|
||||||
Or our mongo url:
|
Or our mongo url:
|
||||||
|
|
||||||
```Swift
|
```swift
|
||||||
let mongoUrl = app.config["keys", "mongo", "url"].string
|
let mongoUrl = app.config["keys", "mongo", "url"].string
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ Let's start with the following JSON files.
|
||||||
|
|
||||||
Please notice that servers.json, and production/servers.json both declare the same keys. host, and port. In our application, we'll call:
|
Please notice that servers.json, and production/servers.json both declare the same keys. host, and port. In our application, we'll call:
|
||||||
|
|
||||||
```Swift
|
```swift
|
||||||
// will load 0.0.0.0 or 127.0.0.1 based on above config
|
// will load 0.0.0.0 or 127.0.0.1 based on above config
|
||||||
let host = app.config["servers", "http", "host"].string
|
let host = app.config["servers", "http", "host"].string
|
||||||
// will load 9000, or environment variable port.
|
// will load 9000, or environment variable port.
|
||||||
|
|
@ -166,7 +166,7 @@ Arguments set through the command line can be accessed through config's cli file
|
||||||
|
|
||||||
would be accessible within your application by using the following:
|
would be accessible within your application by using the following:
|
||||||
|
|
||||||
```Swift
|
```swift
|
||||||
let mongoPassword = app.config["cli", "mongo-password"].string
|
let mongoPassword = app.config["cli", "mongo-password"].string
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -180,6 +180,6 @@ If you want command line arguments set to a file besides "cli", you can use this
|
||||||
|
|
||||||
would be accessible within your application by using the following:
|
would be accessible within your application by using the following:
|
||||||
|
|
||||||
```Swift
|
```swift
|
||||||
let analyticsKey = app.config["keys", "analytics"].string
|
let analyticsKey = app.config["keys", "analytics"].string
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ Valid<Count<T>>
|
||||||
|
|
||||||
## Validators vs. ValidationSuites
|
## Validators vs. ValidationSuites
|
||||||
|
|
||||||
Validators, like Count or Contains can have multiple configurations. For example:
|
Validators, like `Count` or `Contains` can have multiple configurations. For example:
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
let name: Valid<Count<String>> = try "Vapor".validated(by: Count.max(5))
|
let name: Valid<Count<String>> = try "Vapor".validated(by: Count.max(5))
|
||||||
|
|
@ -50,7 +50,7 @@ let name: Valid<Count<String>> = try "Vapor".validated(by: Count.max(5))
|
||||||
|
|
||||||
Here we are validating that the `String` is at most 5 characters long. The type of `Valid<Count>` tells us that the string has been validated to be a certain count, but it does not tell us exactly what that count was. The string could have been validated to be less than three characters or more than one million.
|
Here we are validating that the `String` is at most 5 characters long. The type of `Valid<Count>` tells us that the string has been validated to be a certain count, but it does not tell us exactly what that count was. The string could have been validated to be less than three characters or more than one million.
|
||||||
|
|
||||||
Because of this, `Validators` themselves are not as type safe as some applications might desire. ValidationSuites fix this. They combine multiple `Validators` and/or `ValidationSuites` together to represent exactly what type of data should be considered valid
|
Because of this, `Validators` themselves are not as type safe as some applications might desire. `ValidationSuites` fix this. They combine multiple `Validators` and/or `ValidationSuites` together to represent exactly what type of data should be considered valid
|
||||||
|
|
||||||
## Custom Validator
|
## Custom Validator
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue