• brew install mysql@5.7 && brew link mysql@5.7 --force
  • Package.swift
  1. import PackageDescription
  2.  
  3. // ProjectName
  4. private let kProjectName: String = "ProjectName"
  5.  
  6. let package = Package(
  7. name: kProjectName,
  8. products: [
  9. .executable(name: kProjectName, targets: [kProjectName])
  10. ],
  11. dependencies: [
  12. .package(url: "https://github.com/PerfectlySoft/Perfect-HTTPServer.git", from: "3.0.0"),
  13. .package(url: "https://github.com/PerfectlySoft/Perfect-MySQL.git", from: "3.0.0"),
  14. .package(url: "https://github.com/PerfectlySoft/Perfect-Logger.git", from: "3.0.0"),
  15. ],
  16. targets: [
  17. .target(name: kProjectName, dependencies: ["PerfectHTTPServer", "PerfectMySQL", "PerfectLogger"])
  18. ]
  19. )
  • Sources⁩/⁨<ProjectName>/main.swift
  1. import PerfectLib
  2. import PerfectHTTP
  3. import PerfectHTTPServer
  4. import PerfectLogger
  5.  
  6. //MARK: - Log location
  7. let logPath = "./files/log"
  8. let logDir = Dir(logPath)
  9. if !logDir.exists {
  10. try Dir(logPath).create()
  11. }
  12.  
  13. LogFile.location = "\(logPath)/Server.log"
  14.  
  15. // MARK: - Configure routes
  16. var routes = BasicRoutes().routes
  17.  
  18. // MARK: - Configure server
  19. let server = HTTPServer()
  20. server.addRoutes(routes)
  21. server.serverPort =
  22. server.serverName = "localhost"
  23. server.setResponseFilters([
  24. (try PerfectHTTPServer.HTTPFilter.contentCompression(data: [:]), HTTPFilterPriority.high)])
  25.  
  26. // MARK: - Start server
  27. do {
  28. LogFile.info("Server Start Successful")
  29. try server.start()
  30. } catch let error {
  31. LogFile.error("Failure Start Server:\(error)")
  32. print("Failure Start Server:\(error)")
  33. }
  • Sources⁩/⁨<ProjectName>/ApiOperation.swift
  1. import Foundation
  2. import PerfectLib
  3. import PerfectHTTP
  4. import PerfectHTTPServer
  5.  
  6. // localhost html
  7. private let LocalhostHtml: String = "<html><meta charset=\"UTF-8\"><title>Api Server</title><body>接口服务器<br>V0.0.1</body></html>"
  8.  
  9. class BasicRoutes {
  10. var routes: Routes {
  11. get {
  12. var baseRoutes = Routes()
  13.  
  14. // localhost
  15.  
  16. // Configure one server which:
  17. // * Serves the hello world message at <host>:<port>/
  18. // * Serves static files out of the "./webroot"
  19. // directory (which must be located in the current working directory).
  20. // * Performs content compression on outgoing data when appropriate.
  21.  
  22. baseRoutes.add(method: .get, uri: "/", handler: localhostHandler)
  23. baseRoutes.add(method: .get, uri: "/**", handler: StaticFileHandler(documentRoot: "./webroot", allowResponseFilters: true).handleRequest)
  24.  
  25. // Interface version
  26. baseRoutes.add(method: .get, uri: "/api/v1", handler: apiVersionHandle)
  27.  
  28. return baseRoutes
  29. }
  30. }
  31. // MARK: - localhost
  32. private func localhostHandler(request: HTTPRequest, response: HTTPResponse) {
  33. // Respond with a simple message.
  34. response.setHeader(.contentType, value: "text/html")
  35. response.appendBody(string: LocalhostHtml)
  36. // Ensure that response.completed() is called when your processing is done.
  37. response.completed()
  38. }
  39. // MARK: - Interface version
  40. private func apiVersionHandle(request: HTTPRequest, response: HTTPResponse) {
  41. let successArray: [String: Any] = ["status": , "version": "0.0.1"]
  42. let jsonStr = try! successArray.jsonEncodedString()
  43.  
  44. response.appendBody(string: jsonStr)
  45. response.completed()
  46. }
  47. }
  • swift build
  • swift package generate-xcodeproj

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

  • 启动mysql服务

  $ mysql.server start

  • 初始化mysql配置

  $ mysql_secure_installation

  1. Securing the MySQL server deployment.
  2.  
  3. Connecting to MySQL using a blank password.
  4.  
  5. VALIDATE PASSWORD PLUGIN can be used to test passwords
  6. and improve security. It checks the strength of password
  7. and allows the users to set only those passwords which are
  8. secure enough. Would you like to setup VALIDATE PASSWORD plugin?
  9.  
  10. Press y|Y for Yes, any other key for No: N // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
  11. Please set the password for root here.
  12.  
  13. New password:  // 设置密码
  14.  
  15. Re-enter new password: // 再一次确认密码
  16. By default, a MySQL installation has an anonymous user,
  17. allowing anyone to log into MySQL without having to have
  18. a user account created for them. This is intended only for
  19. testing, and to make the installation go a bit smoother.
  20. You should remove them before moving into a production
  21. environment.
  22.  
  23. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y // 移除不用密码的那个账户
  24. Success.
  25.  
  26. Normally, root should only be allowed to connect from
  27. 'localhost'. This ensures that someone cannot guess at
  28. the root password from the network.
  29.  
  30. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n  //不接受root远程登录账号
  31.  
  32. ... skipping.
  33. By default, MySQL comes with a database named 'test' that
  34. anyone can access. This is also intended only for testing,
  35. and should be removed before moving into a production
  36. environment.
  37.  
  38. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  //删除text数据库
  39. - Dropping test database...
  40. Success.
  41.  
  42. - Removing privileges on test database...
  43. Success.
  44.  
  45. Reloading the privilege tables will ensure that all changes
  46. made so far will take effect immediately.
  47.  
  48. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
  49. Success.
  50.  
  51. 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. 时间转换,django的时间设置,re模块简单校验密码和手机号

    时间转换和密码,手机的re模块简单校验 import re,time def check_userinfo(request): pwd = request.POST.get("pwd&quo ...

  2. Play on Words HDU - 1116 (并查集 + 欧拉通路)

    Play on Words HDU - 1116 Some of the secret doors contain a very interesting word puzzle. The team o ...

  3. BFS:HDU2054-A==B?(字符串的比较)

    A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. U10783 名字被和谐了

    U10783 名字被和谐了 题目背景 众所周知,我们称g是a的约数,当且仅当g是正数且a mod g = 0. 众所周知,若g既是a的约数也是b的约数,我们称g是a.b的一个公约数. 众所周知,a.b ...

  5. 1 - JVM随笔分类(java虚拟机的内存区域分配(一个不断记录和推翻以及再记录的一个过程))

    java虚拟机的内存区域分配   在JVM运行时,类加载器ClassLoader在加载到类的字节码后,交由jvm的执行引擎处理, 执行过程中需要空间来存储数据(类似于Cpu及主存),此时的这段空间的分 ...

  6. SXCPC2018 nucoj2007 和Mengjiji一起攻克难关

    problem #include <algorithm> #include <iostream> #include <cstdio> using namespace ...

  7. 设计模式之序章-UML类图那点事儿

    设计模式之序-UML类图那点事儿 序 打14年年底就像写那么一个系列,用于讲设计模式的,代码基于JAVA语言,最早接触设计模式是大一还是大二来着,那时候网上有人给推荐书,其中就有设计模式,当时给我推荐 ...

  8. ogre3D学习基础17 --- 如何手动创建ogre程序

    建立自己的Ogre程序 一直以来都是使用ExampleApplication.h来写程序,现在来看看它到底有什么神奇的地方. 首先,我们新建一个win32空项目 然后配置环境 最后新建define.c ...

  9. [转载]在Robotium中使用ID

    原文地址:在Robotium中使用ID作者:逍遥云翳 在Robotium的API中不提供使用ID的方式. 如果我们想在Robotium中使用ID就需要自己通过ID来找到控件的实例,然后通过Roboti ...

  10. Feign请求报请求超时

    Feign的底层基于Rabbion实现的,一般情况下直接导入feign的依赖,然后调用feignClient去发送请求,报请求超时. application.yml #hystrix的超时时间 hys ...