• brew install mysql@5.7 && brew link mysql@5.7 --force
  • Package.swift
 import PackageDescription

 // ProjectName
private let kProjectName: String = "ProjectName" let package = Package(
name: kProjectName,
products: [
.executable(name: kProjectName, targets: [kProjectName])
],
dependencies: [
.package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0"),
.package(url: "https://github.com/PerfectlySoft/Perfect-MySQL.git", from: "3.0.0"),
.package(url: "https://github.com/PerfectlySoft/Perfect-Logger.git", from: "3.0.0"),
],
targets: [
.target(name: kProjectName, dependencies: ["PerfectHTTPServer", "PerfectMySQL", "PerfectLogger"])
]
)
  • Sources⁩/⁨<ProjectName>/main.swift
 import PerfectLib
import PerfectHTTP
import PerfectHTTPServer
import PerfectLogger //MARK: - Log location
let logPath = "./files/log"
let logDir = Dir(logPath)
if !logDir.exists {
try Dir(logPath).create()
} LogFile.location = "\(logPath)/Server.log" // MARK: - Configure routes
var routes = BasicRoutes().routes // MARK: - Configure server
let server = HTTPServer()
server.addRoutes(routes)
server.serverPort =
server.serverName = "localhost"
server.setResponseFilters([
(try PerfectHTTPServer.HTTPFilter.contentCompression(data: [:]), HTTPFilterPriority.high)]) // MARK: - Start server
do {
LogFile.info("Server Start Successful")
try server.start()
} catch let error {
LogFile.error("Failure Start Server:\(error)")
print("Failure Start Server:\(error)")
}
  • Sources⁩/⁨<ProjectName>/ApiOperation.swift
 import Foundation
import PerfectLib
import PerfectHTTP
import PerfectHTTPServer // localhost html
private let LocalhostHtml: String = "<html><meta charset=\"UTF-8\"><title>Api Server</title><body>接口服务器<br>V0.0.1</body></html>" class BasicRoutes {
var routes: Routes {
get {
var baseRoutes = Routes() // localhost // Configure one server which:
// * Serves the hello world message at <host>:<port>/
// * Serves static files out of the "./webroot"
// directory (which must be located in the current working directory).
// * Performs content compression on outgoing data when appropriate. baseRoutes.add(method: .get, uri: "/", handler: localhostHandler)
baseRoutes.add(method: .get, uri: "/**", handler: StaticFileHandler(documentRoot: "./webroot", allowResponseFilters: true).handleRequest) // Interface version
baseRoutes.add(method: .get, uri: "/api/v1", handler: apiVersionHandle) return baseRoutes
}
}
// MARK: - localhost
private func localhostHandler(request: HTTPRequest, response: HTTPResponse) {
// Respond with a simple message.
response.setHeader(.contentType, value: "text/html")
response.appendBody(string: LocalhostHtml)
// Ensure that response.completed() is called when your processing is done.
response.completed()
}
// MARK: - Interface version
private func apiVersionHandle(request: HTTPRequest, response: HTTPResponse) {
let successArray: [String: Any] = ["status": , "version": "0.0.1"]
let jsonStr = try! successArray.jsonEncodedString() response.appendBody(string: jsonStr)
response.completed()
}
}
  • swift build
  • swift package generate-xcodeproj

Mac 配置MySql:(管理工具 Sequel Pro)

  • 启动mysql服务

  $ mysql.server start

  • 初始化mysql配置

  $ mysql_secure_installation

 Securing the MySQL server deployment.

 Connecting to MySQL using a blank password.

 VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: N // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
Please set the password for root here. New password:  // 设置密码 Re-enter new password: // 再一次确认密码
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y // 移除不用密码的那个账户
Success. Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n  //不接受root远程登录账号 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  //删除text数据库
- Dropping test database...
Success. - Removing privileges on test database...
Success. Reloading the privilege tables will ensure that all changes
made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success. All done!

Swift Perfect 基础项目的更多相关文章

  1. Swift语法基础入门四(构造函数, 懒加载)

    Swift语法基础入门四(构造函数, 懒加载) 存储属性 具备存储功能, 和OC中普通属性一样 // Swfit要求我们在创建对象时必须给所有的属性初始化 // 如果没办法保证在构造方法中初始化属性, ...

  2. Objective-C 和 Swift 混编项目的小 Tips(一)

    本文主要闲聊一些 Objective-C 和 Swift 混编项目带来的一些潜规则,希望能帮到对此感到疑惑的朋友.下面我们开始进入主题: 命名 官方 Guide 上只是简单叙述(Using Swift ...

  3. 十款不容错过的Swift iOS开源项目及介绍

    1.十款不容错过的Swift iOS开源项目. http://www.csdn.net/article/2014-10-16/2822083-swift-ios-open-source-project ...

  4. [Swift]基础

    [Swift]基础 一, 常用变量 var str = "Hello, playground" //变量 let str1="Hello xmj112288" ...

  5. ios开发——实战Swift篇&简单项目的实现

    学了这么久的swift语法和相关技术,今天忍不住手痒痒就写了一个swift的小项目,这个项目非常简单(只是使用一个UITableView),但是里面的功能却非常有用. 我们要实现的功能是这样的: 程序 ...

  6. Swift之基础知识

    Swift之基础知识 出于对Swift3.0的学习,写下这篇基本语法的笔记.希望能帮助记忆 -0- 这边提供Swift3.0中文教材,资源链接: https://pan.baidu.com/s/1c2 ...

  7. Swift语法基础入门三(函数, 闭包)

    Swift语法基础入门三(函数, 闭包) 函数: 函数是用来完成特定任务的独立的代码块.你给一个函数起一个合适的名字,用来标识函数做什么,并且当函数需要执行的时候,这个名字会被用于“调用”函数 格式: ...

  8. Swift语法基础入门二(数组, 字典, 字符串)

    Swift语法基础入门二(数组, 字典, 字符串) 数组(有序数据的集) *格式 : [] / Int / Array() let 不可变数组 var 可变数组 注意: 不需要改变集合的时候创建不可变 ...

  9. asp.net core系列 59 Ocelot 构建基础项目示例

    一.入门概述 从这篇开始探讨Ocelot,Ocelot是一个.NET API网关,仅适用于.NET Core,用于.NET面向微服务/服务的架构中.当客户端(web站点.ios. app 等)访问we ...

随机推荐

  1. 可怕的万圣节 Linux 命令

    虽然现在不是万圣节,也可以关注一下 Linux 可怕的一面.什么命令可能会显示鬼.巫婆和僵尸的图像?哪个会鼓励"不给糖果就捣蛋"的精神? crypt 好吧,我们一直看到 crypt ...

  2. 25.VUE学习之-单击和双击事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Diycode开源项目 TopicContentActivity分析

    1.效果预览以及布局分析 1.1.实际效果预览 左侧话题列表的布局是通过TopicProvider来实现的,所以当初分析话题列表就没有看到布局. 这里的话题内容不是一个ListView,故要自己布局. ...

  4. 回顾Scrum学习:《Scrum实战》第4次课【全职的Scrum Master】作业

    回顾Scrum学习   1.回顾目标 1.1 期望结果 了解和学习Scrum,为将来换方向打好理论基础 如果能在目前公司引入和推行也很好,但是根据目前公司的文化氛围来看,推行希望不大 把敏捷思想应用到 ...

  5. tensorboard页面显示No dashboards are active for current data set 问题win10系统

    如果问题如上所示,可以试下如下方法: 在文件夹中找到你的logs文件, 在空白处按住“shift”键,右键鼠标(注意鼠标不要选中任何文件),点击“Powershell”打开win10powershel ...

  6. Day24&25&26&27:HTML+CSS

    1.网页得三大组成:HTML(标签.皮影的小人) \CSS(布局,皮影的装束) \JS(动作,皮影的操纵者) 2.HTML目录树 3.HTML-标签 成对<>组成,不区分大小写,自闭合标签 ...

  7. Django中前端界面实现级联查询

    Django前端界面实现级联查询 一.前端界面中 <span scope="col" colspan="6"> 院系:<select id=& ...

  8. 数据结构之c++感悟

    #include<iostream.h> 头文件: #include<iostream.h> #define MAX 1024 typedef int Elemtype; ty ...

  9. 编写高性能React组件-传值篇

    很多人在写React组件的时候没有太在意React组件的性能,使得React做了很多不必要的render,现在我就说说该怎么来编写搞性能的React组件. 首先我们来看一下下面两个组件 import ...

  10. c++ 中pair类模板的用法详解

    pair: 头文件:#include<utility> 类模板:template <class T1, class T2> struct pair 参数:T1是第一个值的数据类 ...