# Kotlin-One **Repository Path**: deali/Kotlin-One ## Basic Information - **Project Name**: Kotlin-One - **Description**: Kotlin学习,代码集合 - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-07-12 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Kotlin One Kotlin语言学习项目 ## Coroutine 首先添加协程库依赖: ```groovy // coroutines compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.3.7' ``` ### 协程参考资料 - [破解 Kotlin 协程(2) - 协程启动篇](https://www.bennyhuo.com/2019/04/08/coroutines-start-mode/) - [官方文档](https://www.kotlincn.net/docs/reference/coroutines/coroutines-guide.html) ## Ktor 官方文档:https://ktor.io/servers/index.html ### 使用配置文件 添加配置文件`application.conf` ```kotlin ktor { deployment { port = 8080 } application { modules = [ kt_one.web.ktor.BlogApp2Kt.module ] } } ``` 在`build.gradle`中添加: ```groovy apply plugin: 'application' mainClassName = 'io.ktor.server.netty.EngineMain' // Starting with 1.0.0-beta-3 ``` ### 返回json 首先添加依赖: ```groovy // json解析 implementation "io.ktor:ktor-gson:$ktor_version" ``` 安装管道: ```kotlin install(ContentNegotiation) { gson { setPrettyPrinting() } } ``` 使用data class作为相应返回: ```kotlin get("/json") { call.respond(MyDataClass("LiHua", "Good good study, day day up!")) } ```