# Sinatra
[![Gem Version](https://badge.fury.io/rb/sinatra.svg)](https://badge.fury.io/rb/sinatra)
[![Build Status](https://secure.travis-ci.org/sinatra/sinatra.svg)](https://travis-ci.org/sinatra/sinatra)
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sinatra&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sinatra&package-manager=bundler&version-scheme=semver)
Sinatra is a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language) for
quickly creating web applications in Ruby with minimal effort:
```ruby
# myapp.rb
require 'sinatra'
get '/' do
'Hello world!'
end
```
Install the gem:
```shell
gem install sinatra
```
And run with:
```shell
ruby myapp.rb
```
View at: [http://localhost:4567](http://localhost:4567)
The code you changed will not take effect until you restart the server.
Please restart the server every time you change or use
[sinatra/reloader](http://www.sinatrarb.com/contrib/reloader).
It is recommended to also run `gem install puma`, which Sinatra will
pick up if available.
## Table of Contents
* [Sinatra](#sinatra)
* [Table of Contents](#table-of-contents)
* [Routes](#routes)
* [Conditions](#conditions)
* [Return Values](#return-values)
* [Custom Route Matchers](#custom-route-matchers)
* [Static Files](#static-files)
* [Views / Templates](#views--templates)
* [Literal Templates](#literal-templates)
* [Available Template Languages](#available-template-languages)
* [Haml Templates](#haml-templates)
* [Erb Templates](#erb-templates)
* [Builder Templates](#builder-templates)
* [Nokogiri Templates](#nokogiri-templates)
* [Sass Templates](#sass-templates)
* [SCSS Templates](#scss-templates)
* [Less Templates](#less-templates)
* [Liquid Templates](#liquid-templates)
* [Markdown Templates](#markdown-templates)
* [Textile Templates](#textile-templates)
* [RDoc Templates](#rdoc-templates)
* [AsciiDoc Templates](#asciidoc-templates)
* [Radius Templates](#radius-templates)
* [Markaby Templates](#markaby-templates)
* [RABL Templates](#rabl-templates)
* [Slim Templates](#slim-templates)
* [Creole Templates](#creole-templates)
* [MediaWiki Templates](#mediawiki-templates)
* [CoffeeScript Templates](#coffeescript-templates)
* [Stylus Templates](#stylus-templates)
* [Yajl Templates](#yajl-templates)
* [WLang Templates](#wlang-templates)
* [Accessing Variables in Templates](#accessing-variables-in-templates)
* [Templates with `yield` and nested layouts](#templates-with-yield-and-nested-layouts)
* [Inline Templates](#inline-templates)
* [Named Templates](#named-templates)
* [Associating File Extensions](#associating-file-extensions)
* [Adding Your Own Template Engine](#adding-your-own-template-engine)
* [Using Custom Logic for Template Lookup](#using-custom-logic-for-template-lookup)
* [Filters](#filters)
* [Helpers](#helpers)
* [Using Sessions](#using-sessions)
* [Session Secret Security](#session-secret-security)
* [Session Config](#session-config)
* [Choosing Your Own Session Middleware](#choosing-your-own-session-middleware)
* [Halting](#halting)
* [Passing](#passing)
* [Triggering Another Route](#triggering-another-route)
* [Setting Body, Status Code and Headers](#setting-body-status-code-and-headers)
* [Streaming Responses](#streaming-responses)
* [Logging](#logging)
* [Mime Types](#mime-types)
* [Generating URLs](#generating-urls)
* [Browser Redirect](#browser-redirect)
* [Cache Control](#cache-control)
* [Sending Files](#sending-files)
* [Accessing the Request Object](#accessing-the-request-object)
* [Attachments](#attachments)
* [Dealing with Date and Time](#dealing-with-date-and-time)
* [Looking Up Template Files](#looking-up-template-files)
* [Configuration](#configuration)
* [Configuring attack protection](#configuring-attack-protection)
* [Available Settings](#available-settings)
* [Environments](#environments)
* [Error Handling](#error-handling)
* [Not Found](#not-found)
* [Error](#error)
* [Rack Middleware](#rack-middleware)
* [Testing](#testing)
* [Sinatra::Base - Middleware, Libraries, and Modular Apps](#sinatrabase---middleware-libraries-and-modular-apps)
* [Modular vs. Classic Style](#modular-vs-classic-style)
* [Serving a Modular Application](#serving-a-modular-application)
* [Using a Classic Style Application with a config.ru](#using-a-classic-style-application-with-a-configru)
* [When to use a config.ru?](#when-to-use-a-configru)
* [Using Sinatra as Middleware](#using-sinatra-as-middleware)
* [Dynamic Application Creation](#dynamic-application-creation)
* [Scopes and Binding](#scopes-and-binding)
* [Application/Class Scope](#applicationclass-scope)
* [Request/Instance Scope](#requestinstance-scope)
* [Delegation Scope](#delegation-scope)
* [Command Line](#command-line)
* [Multi-threading](#multi-threading)
* [Requirement](#requirement)
* [The Bleeding Edge](#the-bleeding-edge)
* [With Bundler](#with-bundler)
* [Versioning](#versioning)
* [Further Reading](#further-reading)
## Routes
In Sinatra, a route is an HTTP method paired with a URL-matching pattern.
Each route is associated with a block:
```ruby
get '/' do
.. show something ..
end
post '/' do
.. create something ..
end
put '/' do
.. replace something ..
end
patch '/' do
.. modify something ..
end
delete '/' do
.. annihilate something ..
end
options '/' do
.. appease something ..
end
link '/' do
.. affiliate something ..
end
unlink '/' do
.. separate something ..
end
```
Routes are matched in the order they are defined. The first route that
matches the request is invoked.
Routes with trailing slashes are different from the ones without:
```ruby
get '/foo' do
# Does not match "GET /foo/"
end
```
Route patterns may include named parameters, accessible via the
`params` hash:
```ruby
get '/hello/:name' do
# matches "GET /hello/foo" and "GET /hello/bar"
# params['name'] is 'foo' or 'bar'
"Hello #{params['name']}!"
end
```
You can also access named parameters via block parameters:
```ruby
get '/hello/:name' do |n|
# matches "GET /hello/foo" and "GET /hello/bar"
# params['name'] is 'foo' or 'bar'
# n stores params['name']
"Hello #{n}!"
end
```
Route patterns may also include splat (or wildcard) parameters, accessible
via the `params['splat']` array:
```ruby
get '/say/*/to/*' do
# matches /say/hello/to/world
params['splat'] # => ["hello", "world"]
end
get '/download/*.*' do
# matches /download/path/to/file.xml
params['splat'] # => ["path/to/file", "xml"]
end
```
Or with block parameters:
```ruby
get '/download/*.*' do |path, ext|
[path, ext] # => ["path/to/file", "xml"]
end
```
Route matching with Regular Expressions:
```ruby
get /\/hello\/([\w]+)/ do
"Hello, #{params['captures'].first}!"
end
```
Or with a block parameter:
```ruby
get %r{/hello/([\w]+)} do |c|
# Matches "GET /meta/hello/world", "GET /hello/world/1234" etc.
"Hello, #{c}!"
end
```
Route patterns may have optional parameters:
```ruby
get '/posts/:format?' do
# matches "GET /posts/" and any extension "GET /posts/json", "GET /posts/xml" etc
end
```
Routes may also utilize query parameters:
```ruby
get '/posts' do
# matches "GET /posts?title=foo&author=bar"
title = params['title']
author = params['author']
# uses title and author vari
logstash-8.5.3-windows-x86-64.zip
需积分: 0 45 浏览量
更新于2022-12-10
收藏 317.34MB ZIP 举报
Logstash 是一个强大的开源数据收集、处理和转发引擎,由 Elastic 公司开发,是 ELK(Elasticsearch、Logstash、Kibana)堆栈的重要组成部分。它主要用于日志管理和分析,能够从各种数据源中采集数据,进行过滤、转换,并将处理后的数据发送到各种目标,如 Elasticsearch、数据库或消息队列。
在提供的压缩包文件"**logstash-8.5.3-windows-x86-64.zip**"中,我们获得的是 Logstash 的 8.5.3 版本,专为 Windows x86-64 平台设计。这个版本包含了所有运行 Logstash 所需的文件,包括二进制文件、配置文件、库文件等。
安装与配置 Logstash:
1. 你需要解压 ZIP 文件到一个适当的目录。
2. 安装 Java 运行环境 (JRE) 或者 Java 开发工具包 (JDK),因为 Logstash 基于 Java。
3. 修改 `config/logstash.yml` 文件来配置 Logstash 的行为,如设置路径、端口和日志级别。
4. 创建或编辑 `config/pipeline.conf` 文件,这是 Logstash 的主要配置文件,用于定义输入、过滤器和输出插件。
输入插件:
Logstash 支持多种输入插件,例如 file input 插件可以从本地文件系统读取日志文件,tcp input 可以监听 TCP 端口接收数据,udp input 可以处理 UDP 数据包。在配置文件中,你需要指定输入插件的类型、参数以及数据源。
过滤插件:
过滤阶段是 Logstash 的核心,可以对数据进行清洗、转换和标准化。例如,grok 过滤器用于解析结构化文本,mutate 过滤器可以修改字段值,date 过滤器则用于识别和转换时间戳。
输出插件:
处理完数据后,Logstash 使用输出插件将数据发送到目标。常见的输出插件有 Elasticsearch 输出,将数据索引到 Elasticsearch 中以便搜索和分析;stdout 输出将数据打印到控制台;file 输出可以将结果写入文件。
Logstash 的工作流程:
Logstash 采用事件驱动模型,每个输入都会生成一个事件,然后通过过滤器进行处理,最后由输出插件将事件发送到目的地。这种模式使得 Logstash 能够灵活地处理各种不同格式和来源的数据。
监控与调试:
为了确保 Logstash 正常运行并优化性能,你可以使用 `--configtest` 命令检查配置文件的语法,`-v` 或 `--verbose` 参数增加日志输出以进行调试。
安全性与扩展性:
Logstash 支持使用 TLS/SSL 加密通信,提高数据传输的安全性。此外,由于其模块化设计,可以通过安装社区提供的额外插件来扩展功能。
Logstash 是一个强大且灵活的数据处理工具,尤其适合日志管理和分析。通过对输入、过滤和输出的定制,它可以适应各种场景,从简单的日志收集到复杂的实时数据分析。正确配置和使用 Logstash,可以极大地提升你的 IT 系统的监控能力和数据洞察力。