Igropyr 项目使用教程
1. 项目的目录结构及介绍
Igropyr 项目的目录结构如下:
Igropyr/
├── src/
│ ├── httpc.c
│ ├── membuf.c
│ └── igropyr.scm
├── include/
│ └── igropyr.h
├── examples/
│ └── example.scm
├── README.md
└── LICENSE
src/
:包含项目的源代码文件,如httpc.c
和membuf.c
,以及 Scheme 文件igropyr.scm
。include/
:包含头文件igropyr.h
。examples/
:包含示例代码example.scm
。README.md
:项目说明文档。LICENSE
:项目许可证文件。
2. 项目的启动文件介绍
项目的启动文件是 src/igropyr.scm
。该文件包含了服务器的主要逻辑和配置。以下是启动文件的关键部分:
(import (igropyr http))
(define (do-when-get-request request)
(res 200 "text/html" "<h1>Hello World</h1>"))
(define (do-when-post-request request)
(res 200 "text/html" "<h1>Post Received</h1>"))
(server
(request do-when-get-request)
(request do-when-post-request)
(set)
(list (cons 'staticpath "/path/to/static")
(cons 'connection 'keep-alive)
(cons 'keepalive 5))
(list (cons 'ip "127.0.0.1")
(cons 'port 8080)))
do-when-get-request
和do-when-post-request
是处理 GET 和 POST 请求的回调函数。server
过程用于启动服务器,接受回调函数、配置列表和监听地址。
3. 项目的配置文件介绍
Igropyr 项目的配置主要通过在启动文件 src/igropyr.scm
中传递配置列表来完成。以下是配置列表的关键部分:
(list (cons 'staticpath "/path/to/static")
(cons 'connection 'keep-alive)
(cons 'keepalive 5))
(list (cons 'ip "127.0.0.1")
(cons 'port 8080))
staticpath
:指定静态文件的路径。connection
:设置连接类型,如keep-alive
。keepalive
:设置保持连接的时间。ip
和port
:指定服务器监听的 IP 地址和端口。
通过这些配置,可以灵活地调整服务器的运行参数。