Browse Source

feat: 添加options和中间件功能

SongZihuan 1 year ago
parent
commit
296935bb6f

+ 0 - 13
.github/FUNDING.yml

@@ -1,13 +0,0 @@
-# These are supported funding model platforms
-
-github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
-patreon: # Replace with a single Patreon username
-open_collective: # Replace with a single Open Collective username
-ko_fi: # Replace with a single Ko-fi username
-tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
-community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
-liberapay: # Replace with a single Liberapay username
-issuehunt: # Replace with a single IssueHunt username
-otechie: # Replace with a single Otechie username
-custom: # https://gitee.com/kevwan/static/raw/master/images/sponsor.jpg
-ethereum: # 0x5052b7f6B937B02563996D23feb69b38D06Ca150 | kevwan

+ 0 - 40
.github/ISSUE_TEMPLATE/bug_report.md

@@ -1,40 +0,0 @@
----
-name: Bug report
-about: Create a report to help us improve
-title: ''
-labels: ''
-assignees: ''
-
----
-
-**Describe the bug**
-A clear and concise description of what the bug is.
-
-**To Reproduce**
-Steps to reproduce the behavior, if applicable:
-
-1. The code is
-
-   ```go
-   
-   ```
-
-2. The error is
-
-   ```
-   
-   ```
-
-**Expected behavior**
-A clear and concise description of what you expected to happen.
-
-**Screenshots**
-If applicable, add screenshots to help explain your problem.
-
-**Environments (please complete the following information):**
- - OS: [e.g. Linux]
- - go-zero version [e.g. 1.2.1]
- - goctl version [e.g. 1.2.1, optional]
-
-**More description**
-Add any other context about the problem here.

+ 0 - 20
.github/ISSUE_TEMPLATE/feature_request.md

@@ -1,20 +0,0 @@
----
-name: Feature request
-about: Suggest an idea for this project
-title: ''
-labels: ''
-assignees: ''
-
----
-
-**Is your feature request related to a problem? Please describe.**
-A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
-
-**Describe the solution you'd like**
-A clear and concise description of what you want to happen.
-
-**Describe alternatives you've considered**
-A clear and concise description of any alternative solutions or features you've considered.
-
-**Additional context**
-Add any other context or screenshots about the feature request here.

+ 0 - 10
.github/ISSUE_TEMPLATE/question.md

@@ -1,10 +0,0 @@
----
-name: Question
-about: Ask a question on using go-zero or goctl
-title: ''
-labels: ''
-assignees: ''
-
----
-
-

+ 0 - 15
.github/dependabot.yml

@@ -1,15 +0,0 @@
-# To get started with Dependabot version updates, you'll need to specify which
-# package ecosystems to update and where the package manifests are located.
-# Please see the documentation for all configuration options:
-# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
-
-version: 2
-updates:
-  - package-ecosystem: "gomod" # See documentation for possible values
-    directory: "/" # Location of package manifests
-    schedule:
-      interval: "daily"
-  - package-ecosystem: "gomod" # See documentation for possible values
-    directory: "/tools/goctl" # Location of package manifests
-    schedule:
-      interval: "daily"

+ 0 - 67
.github/workflows/codeql-analysis.yml

@@ -1,67 +0,0 @@
-# For most projects, this workflow file will not need changing; you simply need
-# to commit it to your repository.
-#
-# You may wish to alter this file to override the set of languages analyzed,
-# or to provide custom queries or build logic.
-#
-# ******** NOTE ********
-# We have attempted to detect the languages in your repository. Please check
-# the `language` matrix defined below to confirm you have the correct set of
-# supported CodeQL languages.
-#
-name: "CodeQL"
-
-on:
-  push:
-    branches: [ master ]
-  pull_request:
-    # The branches below must be a subset of the branches above
-    branches: [ master ]
-  schedule:
-    - cron: '18 19 * * 6'
-
-jobs:
-  analyze:
-    name: Analyze
-    runs-on: ubuntu-latest
-
-    strategy:
-      fail-fast: false
-      matrix:
-        language: [ 'go' ]
-        # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
-        # Learn more:
-        # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
-
-    steps:
-    - name: Checkout repository
-      uses: actions/checkout@v4
-
-    # Initializes the CodeQL tools for scanning.
-    - name: Initialize CodeQL
-      uses: github/codeql-action/init@v2
-      with:
-        languages: ${{ matrix.language }}
-        # If you wish to specify custom queries, you can do so here or in a config file.
-        # By default, queries listed here will override any specified in a config file.
-        # Prefix the list here with "+" to use these queries and those in the config file.
-        # queries: ./path/to/local/query, your-org/your-repo/queries@main
-
-    # Autobuild attempts to build any compiled languages  (C/C++, C#, or Java).
-    # If this step fails, then you should remove it and run the build manually (see below)
-    - name: Autobuild
-      uses: github/codeql-action/autobuild@v2
-
-    # ℹ️ Command-line programs to run using the OS shell.
-    # 📚 https://git.io/JvXDl
-
-    # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
-    #    and modify them (or add more) to build your code if your project
-    #    uses a compiled language
-
-    #- run: |
-    #   make bootstrap
-    #   make release
-
-    - name: Perform CodeQL Analysis
-      uses: github/codeql-action/analyze@v2

+ 0 - 65
.github/workflows/go.yml

@@ -1,65 +0,0 @@
-name: Go
-
-on:
-  push:
-    branches: [ master ]
-  pull_request:
-    branches: [ master ]
-
-jobs:
-  test-linux:
-    name: Linux
-    runs-on: ubuntu-latest
-    steps:
-      - name: Check out code into the Go module directory
-        uses: actions/checkout@v4
-
-      - name: Set up Go 1.x
-        uses: actions/setup-go@v4
-        with:
-          go-version: 1.19
-          check-latest: true
-          cache: true
-        id: go
-
-      - name: Get dependencies
-        run: |
-          go get -v -t -d ./...
-
-      - name: Lint
-        run: |
-          go vet -stdmethods=false $(go list ./...)
-
-          go mod tidy
-          if ! test -z "$(git status --porcelain)"; then
-            echo "Please run 'go mod tidy'"
-            exit 1
-          fi
-
-      - name: Test
-        run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
-
-      - name: Codecov
-        uses: codecov/codecov-action@v3
-
-  test-win:
-    name: Windows
-    runs-on: windows-latest
-    steps:
-      - name: Checkout codebase
-        uses: actions/checkout@v4
-
-      - name: Set up Go 1.x
-        uses: actions/setup-go@v4
-        with:
-          # use 1.19 to guarantee Go 1.19 compatibility
-          go-version: 1.19
-          check-latest: true
-          cache: true
-
-      - name: Test
-        run: |
-          go mod verify
-          go mod download
-          go test ./...
-          cd tools/goctl && go build -v goctl.go

+ 0 - 18
.github/workflows/issue-translator.yml

@@ -1,18 +0,0 @@
-name: 'issue-translator'
-on: 
-  issue_comment: 
-    types: [created]
-  issues: 
-    types: [opened]
-
-jobs:
-  build:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: usthe/issues-translate-action@v2.7
-        with:
-          IS_MODIFY_TITLE: true
-          # not require, default false, . Decide whether to modify the issue title
-          # if true, the robot account @Issues-translate-bot must have modification permissions, invite @Issues-translate-bot to your project or use your custom bot.
-          CUSTOM_BOT_NOTE: Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿
-          # not require. Customize the translation robot prefix message.

+ 0 - 19
.github/workflows/issues.yml

@@ -1,19 +0,0 @@
-name: Close inactive issues
-on:
-  schedule:
-    - cron: "30 1 * * *"
-
-jobs:
-  close-issues:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/stale@v8
-        with:
-          days-before-issue-stale: 365
-          days-before-issue-close: 90
-          stale-issue-label: "stale"
-          stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
-          close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
-          days-before-pr-stale: -1
-          days-before-pr-close: -1
-          repo-token: ${{ secrets.GITHUB_TOKEN }}

+ 0 - 28
.github/workflows/release.yaml

@@ -1,28 +0,0 @@
-on:
-  push:
-    tags:
-      - "tools/goctl/*"
-jobs:
-  releases-matrix:
-    name: Release goctl binary
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        # build and publish in parallel: linux/386, linux/amd64, linux/arm64,
-        # windows/386, windows/amd64, windows/arm64, darwin/amd64, darwin/arm64
-        goos: [ linux, windows, darwin ]
-        goarch: [ "386", amd64, arm64 ]
-        exclude:
-          - goarch: "386"
-            goos: darwin
-    steps:
-      - uses: actions/checkout@v4
-      - uses: zeromicro/go-zero-release-action@master
-        with:
-          github_token: ${{ secrets.GITHUB_TOKEN }}
-          goos: ${{ matrix.goos }}
-          goarch: ${{ matrix.goarch }}
-          goversion: "https://dl.google.com/go/go1.19.13.linux-amd64.tar.gz"
-          project_path: "tools/goctl"
-          binary_name: "goctl"
-          extra_files: tools/goctl/readme.md tools/goctl/readme-cn.md

+ 0 - 19
.github/workflows/reviewdog.yml

@@ -1,19 +0,0 @@
-name: reviewdog
-on: [pull_request]
-jobs:
-  staticcheck:
-    name: runner / staticcheck
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v4
-      - uses: reviewdog/action-staticcheck@v1
-        with:
-          github_token: ${{ secrets.github_token }}
-          # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
-          reporter: github-pr-review
-          # Report all results.
-          filter_mode: nofilter
-          # Exit with 1 when it find at least one finding.
-          fail_on_error: true
-          # Set staticcheck flags
-          staticcheck_flags: -checks=inherit,-SA1019,-SA1029,-SA5008

+ 0 - 76
CONTRIBUTING.md

@@ -1,76 +0,0 @@
-# 🚀 Contributing to go-zero
-
-Welcome to the go-zero community! We're thrilled to have you here. Contributing to our project is a fantastic way to be a part of the go-zero journey. Let's make this guide exciting and fun!
-
-## 📜 Before You Dive In
-
-### 🤝 Code of Conduct
-
-Let's start on the right foot. Please take a moment to read and embrace our [Code of Conduct](/code-of-conduct.md). We're all about creating a welcoming and respectful environment.
-
-### 🌟 Community Expectations
-
-At go-zero, we're like a close-knit family, and we believe in creating a healthy, friendly, and productive atmosphere. It's all about sharing knowledge and building amazing things together.
-
-## 🚀 Getting Started
-
-Get your adventure rolling! Here's how to begin:
-
-1. 🍴 **Fork the Repository**: Head over to the GitHub repository and fork it to your own space.
-
-2. 🛠️ **Make Your Magic**: Work your magic in your forked repository. Create new features, squash bugs, or improve documentation - it's your world to conquer!
-
-3. 🚀 **Submit a PR (Pull Request)**: When you're ready to unveil your creation, submit a Pull Request. We can't wait to see your awesome work!
-
-## 🌟 Your First Contribution
-
-We're here to guide you on your quest to become a go-zero contributor. Whether you want to file issues, develop features, or tame some critical bugs, we've got you covered.
-
-If you have questions or need guidance at any stage, don't hesitate to [open an issue](https://github.com/zeromicro/go-zero/issues/new/choose).
-
-## 🔍 Find Something to Work On
-
-Ready to dive into the action? There are several ways to contribute:
-
-### 💼 Find a Good First Topic
-
-Discover easy-entry issues labeled as [help wanted](https://github.com/zeromicro/go-zero/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) or [good first issue](https://github.com/zeromicro/go-zero/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22). These issues are perfect for newcomers and don't require deep knowledge of the system. We're here to assist you with these tasks.
-
-### 🪄 Work on an Issue
-
-Once you've picked an issue that excites you, let us know by commenting on it. Our maintainers will assign it to you, and you can embark on your mission!
-
-### 📢 File an Issue
-
-Reporting an issue is just as valuable as code contributions. If you discover a problem, don't hesitate to [open an issue](https://github.com/zeromicro/go-zero/issues/new/choose). Be sure to follow our guidelines when submitting an issue.
-
-## 🎯 Contributor Workflow
-
-Here's a rough guide to your contributor journey:
-
-1. 🌱 Create a New Branch: Start by creating a topic branch, usually based on the 'master' branch. This is where your contribution will grow.
-
-2. 💡 Make Commits: Commit your work in logical units. Each commit should tell a story.
-
-3. 🚀 Push Changes: Push the changes in your topic branch to your personal fork of the repository.
-
-4. 📦 Submit a Pull Request: When your creation is complete, submit a Pull Request to the [go-zero repository](https://github.com/zeromicro/go-zero).
-
-## 🌠 Creating Pull Requests
-
-Pull Requests (PRs) are your way of making a grand entrance with your contribution. Here's how to do it:
-
-- 💼 Format Your Code: Ensure your code is beautifully formatted with `gofmt`.
-- 🏃 Run Tests: Verify that your changes pass all the tests, including data race tests. Run `go test -race ./...` for the ultimate validation.
-
-## 👁️‍🗨️ Code Review
-
-Getting your PR reviewed is the final step before your contribution becomes part of go-zero's magical world. To make the process smooth, keep these things in mind:
-
-- 🧙‍♀️ Follow Good Coding Practices: Stick to [good coding guidelines](https://github.com/golang/go/wiki/CodeReviewComments).
-- 📝 Write Awesome Commit Messages: Craft [impressive commit messages](https://chris.beams.io/posts/git-commit/) - they're like spells in the wizard's book!
-- 🔍 Break It Down: For larger changes, consider breaking them into a series of smaller, logical patches. Each patch should make an understandable and meaningful improvement.
-
-Congratulations on your contribution journey! We're thrilled to have you as part of our go-zero community. Let's make amazing things together! 🌟
-
-Now, go out there and start your adventure! If you have any more magical ideas to enhance this guide, please share them. 🔥

+ 0 - 127
code-of-conduct.md

@@ -1,127 +0,0 @@
-
-# Contributor Covenant Code of Conduct
-
-## Our Pledge
-
-We as members, contributors, and leaders pledge to make participation in our
-community a harassment-free experience for everyone, regardless of age, body
-size, visible or invisible disability, ethnicity, sex characteristics, gender
-identity and expression, level of experience, education, socio-economic status,
-nationality, personal appearance, race, caste, color, religion, or sexual
-identity and orientation.
-
-We pledge to act and interact in ways that contribute to an open, welcoming,
-diverse, inclusive, and healthy community.
-
-## Our Standards
-
-Examples of behavior that contributes to a positive environment for our
-community include:
-
-* Demonstrating empathy and kindness toward other people
-* Being respectful of differing opinions, viewpoints, and experiences
-* Giving and gracefully accepting constructive feedback
-* Accepting responsibility and apologizing to those affected by our mistakes,
-  and learning from the experience
-* Focusing on what is best not just for us as individuals, but for the overall
-  community
-
-Examples of unacceptable behavior include:
-
-* The use of sexualized language or imagery, and sexual attention or advances of
-  any kind
-* Trolling, insulting or derogatory comments, and personal or political attacks
-* Public or private harassment
-* Publishing others' private information, such as a physical or email address,
-  without their explicit permission
-* Other conduct which could reasonably be considered inappropriate in a
-  professional setting
-
-## Enforcement Responsibilities
-
-Community leaders are responsible for clarifying and enforcing our standards of
-acceptable behavior and will take appropriate and fair corrective action in
-response to any behavior that they deem inappropriate, threatening, offensive,
-or harmful.
-
-Community leaders have the right and responsibility to remove, edit, or reject
-comments, commits, code, wiki edits, issues, and other contributions that are
-not aligned to this Code of Conduct, and will communicate reasons for moderation
-decisions when appropriate.
-
-## Scope
-
-This Code of Conduct applies within all community spaces, and also applies when
-an individual is officially representing the community in public spaces.
-Examples of representing our community include using an official e-mail address,
-posting via an official social media account, or acting as an appointed
-representative at an online or offline event.
-
-## Enforcement
-
-Instances of abusive, harassing, or otherwise unacceptable behavior may be
-reported to the community leaders responsible for enforcement at
-[INSERT CONTACT METHOD].
-All complaints will be reviewed and investigated promptly and fairly.
-
-All community leaders are obligated to respect the privacy and security of the
-reporter of any incident.
-
-## Enforcement Guidelines
-
-Community leaders will follow these Community Impact Guidelines in determining
-the consequences for any action they deem in violation of this Code of Conduct:
-
-### 1. Correction
-
-**Community Impact**: Use of inappropriate language or other behavior deemed
-unprofessional or unwelcome in the community.
-
-**Consequence**: A private, written warning from community leaders, providing
-clarity around the nature of the violation and an explanation of why the
-behavior was inappropriate. A public apology may be requested.
-
-### 2. Warning
-
-**Community Impact**: A violation through a single incident or series of
-actions.
-
-**Consequence**: A warning with consequences for continued behavior. No
-interaction with the people involved, including unsolicited interaction with
-those enforcing the Code of Conduct, for a specified period of time. This
-includes avoiding interactions in community spaces as well as external channels
-like social media. Violating these terms may lead to a temporary or permanent
-ban.
-
-### 3. Temporary Ban
-
-**Community Impact**: A serious violation of community standards, including
-sustained inappropriate behavior.
-
-**Consequence**: A temporary ban from any sort of interaction or public
-communication with the community for a specified period of time. No public or
-private interaction with the people involved, including unsolicited interaction
-with those enforcing the Code of Conduct, is allowed during this period.
-Violating these terms may lead to a permanent ban.
-
-### 4. Permanent Ban
-
-**Community Impact**: Demonstrating a pattern of violation of community
-standards, including sustained inappropriate behavior, harassment of an
-individual, or aggression toward or disparagement of classes of individuals.
-
-**Consequence**: A permanent ban from any sort of public interaction within the
-community.
-
-## Attribution
-
-This Code of Conduct is adapted from the [Contributor Covenant][homepage],
-version 2.1, available at
-[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
-
-Community Impact Guidelines were inspired by
-[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
-
-For answers to common questions about this code of conduct, see the FAQ at
-[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
-[https://www.contributor-covenant.org/translations][translations].

BIN
core/logx/2023-11-13.gz


+ 0 - 0
core/logx/CD01CB7D-2705-4F3F-889E-86219BF56F10/Song-G7/access.log


+ 0 - 0
core/logx/CD01CB7D-2705-4F3F-889E-86219BF56F10/Song-G7/error.log


+ 0 - 0
core/logx/CD01CB7D-2705-4F3F-889E-86219BF56F10/Song-G7/severe.log


+ 0 - 0
core/logx/CD01CB7D-2705-4F3F-889E-86219BF56F10/Song-G7/slow.log


+ 0 - 0
core/logx/CD01CB7D-2705-4F3F-889E-86219BF56F10/Song-G7/stat.log


+ 0 - 334
readme-cn.md

@@ -1,334 +0,0 @@
-<img align="right" width="150px" src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/go-zero.png">
-
-# go-zero
-
-***缩短从需求到上线的距离***
-
-[English](readme.md) | 简体中文
-
-[![Go](https://github.com/zeromicro/go-zero/workflows/Go/badge.svg?branch=master)](https://github.com/zeromicro/go-zero/actions)
-[![Go Report Card](https://goreportcard.com/badge/github.com/zeromicro/go-zero)](https://goreportcard.com/report/github.com/zeromicro/go-zero)
-[![goproxy](https://goproxy.cn/stats/github.com/tal-tech/go-zero/badges/download-count.svg)](https://goproxy.cn/stats/github.com/tal-tech/go-zero/badges/download-count.svg)
-[![codecov](https://codecov.io/gh/zeromicro/go-zero/branch/master/graph/badge.svg)](https://codecov.io/gh/zeromicro/go-zero)
-[![Release](https://img.shields.io/github/v/release/zeromicro/go-zero.svg?style=flat-square)](https://github.com/zeromicro/go-zero)
-[![Go Reference](https://pkg.go.dev/badge/github.com/zeromicro/go-zero.svg)](https://pkg.go.dev/github.com/zeromicro/go-zero)
-[![Awesome Go](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go)
-[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
-
-<a href="https://www.producthunt.com/posts/go-zero?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-go&#0045;zero" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=334030&theme=light" alt="go&#0045;zero - A&#0032;web&#0032;&#0038;&#0032;rpc&#0032;framework&#0032;written&#0032;in&#0032;Go&#0046; | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
-
-## 0. go-zero 介绍
-
-go-zero(收录于 CNCF 云原生技术全景图:[https://landscape.cncf.io/?selected=go-zero](https://landscape.cncf.io/?selected=go-zero))是一个集成了各种工程实践的 web 和 rpc 框架。通过弹性设计保障了大并发服务端的稳定性,经受了充分的实战检验。
-
-go-zero 包含极简的 API 定义和生成工具 goctl,可以根据定义的 api 文件一键生成 Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript 代码,并可直接运行。
-
-使用 go-zero 的好处:
-
-* 轻松获得支撑千万日活服务的稳定性
-* 内建级联超时控制、限流、自适应熔断、自适应降载等微服务治理能力,无需配置和额外代码
-* 微服务治理中间件可无缝集成到其它现有框架使用
-* 极简的 API 描述,一键生成各端代码
-* 自动校验客户端请求参数合法性
-* 大量微服务治理和并发工具包
-
-![架构图](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/architecture.png)
-
-## 1. go-zero 框架背景
-
-18 年初,我们决定从 `Java+MongoDB` 的单体架构迁移到微服务架构,经过仔细思考和对比,我们决定:
-
-* 基于 Go 语言
-  * 高效的性能
-  * 简洁的语法
-  * 广泛验证的工程效率
-  * 极致的部署体验
-  * 极低的服务端资源成本
-* 自研微服务框架
-  * 有过很多微服务框架自研经验
-  * 需要有更快速的问题定位能力
-  * 更便捷的增加新特性
-
-## 2. go-zero 框架设计思考
-
-对于微服务框架的设计,我们期望保障微服务稳定性的同时,也要特别注重研发效率。所以设计之初,我们就有如下一些准则:
-
-* 保持简单,第一原则
-* 弹性设计,面向故障编程
-* 工具大于约定和文档
-* 高可用、高并发、易扩展
-* 对业务开发友好,封装复杂度
-* 约束做一件事只有一种方式
-
-我们经历不到半年时间,彻底完成了从 `Java+MongoDB` 到 `Golang+MySQL` 为主的微服务体系迁移,并于 18 年 8 月底完全上线,稳定保障了业务后续迅速增长,确保了整个服务的高可用。
-
-## 3. go-zero 项目实现和特点
-
-go-zero 是一个集成了各种工程实践的包含 web 和 rpc 框架,有如下主要特点:
-
-* 强大的工具支持,尽可能少的代码编写
-* 极简的接口
-* 完全兼容 net/http
-* 支持中间件,方便扩展
-* 高性能
-* 面向故障编程,弹性设计
-* 内建服务发现、负载均衡
-* 内建限流、熔断、降载,且自动触发,自动恢复
-* API 参数自动校验
-* 超时级联控制
-* 自动缓存控制
-* 链路跟踪、统计报警等
-* 高并发支撑,稳定保障了疫情期间每天的流量洪峰
-
-如下图,我们从多个层面保障了整体服务的高可用:
-
-![弹性设计](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/resilience.jpg)
-
-## 4. 我们使用 go-zero 的基本架构图
-
-<img width="1067" alt="image" src="https://user-images.githubusercontent.com/1918356/171880582-11a86658-41c3-466c-95e7-7b1220eecc52.png">
-
-觉得不错的话,别忘 **star** 👏
-
-## 5. Installation
-
-在项目目录下通过如下命令安装:
-
-```shell
-GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro/go-zero
-```
-
-## 6. Quick Start
-
-0. 完整示例请查看
-
-    [快速构建高并发微服务](https://github.com/zeromicro/zero-doc/blob/main/doc/shorturl.md)
-
-    [快速构建高并发微服务 - 多 RPC 版](https://github.com/zeromicro/zero-doc/blob/main/docs/zero/bookstore.md)
-
-1. 安装 goctl 工具
-
-    `goctl` 读作 `go control`,不要读成 `go C-T-L`。`goctl` 的意思是不要被代码控制,而是要去控制它。其中的 `go` 不是指 `golang`。在设计 `goctl` 之初,我就希望通过 `工具` 来解放我们的双手👈
-
-    ```shell
-    # Go
-    GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest
-    
-    # For Mac
-    brew install goctl
-    
-    # docker for amd64 architecture
-    docker pull kevinwan/goctl
-    # run goctl like
-    docker run --rm -it -v `pwd`:/app kevinwan/goctl goctl --help
-    
-    # docker for arm64(Mac) architecture
-    docker pull kevinwan/goctl:latest-arm64
-    # run goctl like
-    docker run --rm -it -v `pwd`:/app kevinwan/goctl:latest-arm64 goctl --help
-    ```
-    
-    确保 goctl 可执行
-    
-2. 快速生成 api 服务
-
-    ```shell
-    goctl api new greet
-    cd greet
-    go mod init
-    go mod tidy
-    go run greet.go -f etc/greet-api.yaml
-    ```
-
-    默认侦听在 `8888` 端口(可以在配置文件里修改),可以通过 `curl` 请求:
-
-    ```shell
-    curl -i http://localhost:8888/from/you
-    ```
-
-    返回如下:
-
-    ```http
-    HTTP/1.1 200 OK
-    Content-Type: application/json
-    Date: Thu, 22 Oct 2020 14:03:18 GMT
-    Content-Length: 14
-
-    {"message":""}
-    ```
-
-    编写业务代码:
-
-      * api 文件定义了服务对外 HTTP 接口,可参考 [api 规范](https://github.com/zeromicro/zero-doc/blob/main/docs/zero/goctl-api.md)
-      * 可以在 `servicecontext.go` 里面传递依赖给 logic,比如 mysql, redis 等
-      * 在 api 定义的 `get/post/put/delete` 等请求对应的 logic 里增加业务处理逻辑
-
-3. 可以根据 api 文件生成前端需要的 Java, TypeScript, Dart, JavaScript 代码
-
-    ```shell
-    goctl api java -api greet.api -dir greet
-    goctl api dart -api greet.api -dir greet
-    ...
-    ```
-
-## 7. Benchmark
-
-![benchmark](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/benchmark.png)
-
-[测试代码见这里](https://github.com/smallnest/go-web-framework-benchmark)
-
-## 8. 文档
-
-* API 文档
-
-  [https://go-zero.dev/cn/](https://go-zero.dev/cn/)
-
-* awesome 系列(更多文章见『微服务实践』公众号)
-
-  * [快速构建高并发微服务](https://github.com/zeromicro/zero-doc/blob/main/doc/shorturl.md)
-  * [快速构建高并发微服务 - 多 RPC 版](https://github.com/zeromicro/zero-doc/blob/main/docs/zero/bookstore.md)
-  * [goctl 使用帮助](https://github.com/zeromicro/zero-doc/blob/main/doc/goctl.md)
-  * [Examples](https://github.com/zeromicro/zero-examples)
-
-* 精选 `goctl` 插件
-
-  | 插件    | 用途  |
-  | ------------- |:-------------|
-  | [goctl-swagger](https://github.com/zeromicro/goctl-swagger) | 一键生成 `api` 的 `swagger` 文档 |
-  | [goctl-android](https://github.com/zeromicro/goctl-android) | 生成 `java (android)` 端 `http client` 请求代码 |
-  | [goctl-go-compact](https://github.com/zeromicro/goctl-go-compact) | 合并 `api` 里同一个 `group` 里的 `handler` 到一个 `go` 文件 |
-
-## 9. go-zero 用户
-
-go-zero 已被许多公司用于生产部署,接入场景如在线教育、电商业务、游戏、区块链等,目前为止,已使用 go-zero 的公司包括但不限于:
-
->1. 好未来
->2. 上海晓信信息科技有限公司(晓黑板)
->3. 上海玉数科技有限公司
->4. 常州千帆网络科技有限公司
->5. 上班族科技
->6. 英雄体育(VSPN)
->7. githubmemory
->8. 释空(上海)品牌策划有限公司(senkoo)
->9. 鞍山三合众鑫科技有限公司
->10. 广州星梦工场网络科技有限公司
->11. 杭州复杂美科技有限公司
->12. 赛凌科技
->13. 捞月狗
->14. 浙江三合通信科技有限公司
->15. 爱克萨
->16. 郑州众合互联信息技术有限公司
->17. 三七游戏
->18. 成都创道夫科技有限公司
->19. 联想Lenovo
->20. 云犀
->21. 高盈国际
->22. 北京中科生活服务有限公司
->23. Indochat 印尼艾希英
->24. 数赞
->25. 量冠科技
->26. 杭州又拍云科技有限公司
->27. 深圳市点购电子商务控股股份有限公司
->28. 深圳市宁克沃德科技有限公司
->29. 桂林优利特医疗电子有限公司
->30. 成都智橙互动科技有限公司
->31. 深圳市班班科技有限公司
->32. 飞视(苏州)数字技术有限公司
->33. 上海鲸思智能科技有限公司
->34. 南宁宸升计算机科技有限公司
->35. 秦皇岛2084team
->36. 天翼云股份有限公司
->37. 南京速优云信息科技有限公司
->38. 北京小鸦科技有限公司
->39. 深圳无边界技术有限公司
->40. 马鞍山百助网络科技有限公司
->41. 上海阿莫尔科技有限公司
->42. 发明者量化
->43. 济南超级盟网络科技有限公司
->44. 苏州互盟信息存储技术有限公司
->45. 成都艾途教育科技集团有限公司
->46. 上海游族网络
->47. 深信服
->48. 中免日上科技互联有限公司
->49. ECLOUDVALLEY TECHNOLOGY (HK) LIMITED
->50. 馨科智(深圳)科技有限公司
->51. 成都松珀科技有限公司
->52. 亿景智联
->53. 上海扩博智能技术有限公司
->54. 一犀科技成都有限公司
->55. 北京术杰科技有限公司
->56. 时代脉搏网络科技(云浮市)有限公司
->57. 店有帮
->58. 七牛云
->59. 费芮网络
->60. 51CTO
->61. 聿旌科技
->62. 山东胜软科技股份有限公司
->63. 上海芯果科技有限公司(好特卖)
->64. 成都高鹿科技有限公司
->65. 飞视(苏州)数字技术有限公司
->66. 上海幻析信息科技有限公司
->67. 统信软件技术有限公司
->68. 得物
->69. 鼎翰文化股份有限公司
->70. 茶码纹化(云南)科技发展有限公司
->71. 湖南度思信息技术有限公司
->72. 深圳圆度
->73. 武汉沃柒科技有限公司(茄椒)
->74. 驭势科技
->75. 叮当跳动
->76. Keep
->77. simba innovation
->78. ZeroCMF
->79. 安徽寻梦投资发展集团
->80. 广州腾思信息科技有限公司
->81. 广州机智云物联网科技有限公司
->82. 厦门亿联网络技术股份有限公司
->83. 北京麦芽田网络科技有限公司
->84. 佛山市振联科技有限公司
->85. 苏州智言信息科技有限公司
->86. 中国移动上海产业研究院
->87. 天枢数链(浙江)科技有限公司
->88. 北京娱人共享智能科技有限公司
->89. 北京数智方科技有限公司
->90. 元匠科技
->91. 宁波甬风信息科技有限公司
->92. 深圳市万佳安物联科技股份有限公司
->93. 武侯区编程之美软件开发工作室
->94. 西安交通大学智慧能源与碳中和研究中心
->95. 成都创软科技有限责任公司
-
-如果贵公司也已使用 go-zero,欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
-
-## 10. CNCF 云原生技术全景图
-
-<p float="left">
-<img src="https://landscape.cncf.io/images/left-logo.svg" width="150"/>&nbsp;&nbsp;&nbsp;
-<img src="https://landscape.cncf.io/images/right-logo.svg" width="200"/>
-</p>
-
-go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape.cncf.io/?selected=go-zero)。
-
-## 11. 微信公众号
-
-`go-zero` 相关文章和视频都会在 `微服务实践` 公众号整理呈现,欢迎扫码关注 👏
-
-<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/zeromicro.jpg" alt="wechat" width="600" />
-
-## 12. 微信交流群
-
-如果文档中未能覆盖的任何疑问,欢迎您在群里提出,我们会尽快答复。
-
-您可以在群内提出使用中需要改进的地方,我们会考虑合理性并尽快修改。
-
-如果您发现 ***bug*** 请及时提 ***issue***,我们会尽快确认并修改。
-
-加群之前有劳点一下 ***star***,一个小小的 ***star*** 是作者们回答海量问题的动力!🤝
-
-<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/wechat.jpg" alt="wechat" width="300" />
-
-## 13. 赞助一下👍
-
-如果觉得项目有帮助,可以请作者喝杯咖啡 🍹
-
-<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/sponsor.png" alt="wechat" width="300" />

+ 8 - 263
readme.md

@@ -1,263 +1,8 @@
-# go-zero
-<p align="center">
-<img align="center" width="150px" src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/go-zero.png">
-</p>
-
-go-zero is a web and rpc framework with lots of builtin engineering practices. It’s born to ensure the stability of the busy services with resilience design and has been serving sites with tens of millions of users for years.
-
-<div align=center>
-
-[![Go](https://github.com/zeromicro/go-zero/workflows/Go/badge.svg?branch=master)](https://github.com/zeromicro/go-zero/actions)
-[![codecov](https://codecov.io/gh/zeromicro/go-zero/branch/master/graph/badge.svg)](https://codecov.io/gh/zeromicro/go-zero)
-[![Go Report Card](https://goreportcard.com/badge/github.com/zeromicro/go-zero)](https://goreportcard.com/report/github.com/zeromicro/go-zero)
-[![Release](https://img.shields.io/github/v/release/zeromicro/go-zero.svg?style=flat-square)](https://github.com/zeromicro/go-zero)
-[![Go Reference](https://pkg.go.dev/badge/github.com/zeromicro/go-zero.svg)](https://pkg.go.dev/github.com/zeromicro/go-zero)
-[![Awesome Go](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/avelino/awesome-go)
-[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
-[![Discord](https://img.shields.io/discord/794530774463414292?label=chat&logo=discord)](https://discord.gg/4JQvC5A4Fe)
-
-</div>
-
-
-## 🤷‍ What is go-zero?
-English | [简体中文](readme-cn.md)
-
-<a href="https://www.producthunt.com/posts/go-zero?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-go&#0045;zero" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=334030&theme=light" alt="go&#0045;zero - A&#0032;web&#0032;&#0038;&#0032;rpc&#0032;framework&#0032;written&#0032;in&#0032;Go&#0046; | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
-
-
-go-zero (listed in CNCF Landscape: [https://landscape.cncf.io/?selected=go-zero](https://landscape.cncf.io/?selected=go-zero)) is a web and rpc framework with lots of builtin engineering practices. It’s born to ensure the stability of the busy services with resilience design and has been serving sites with tens of millions of users for years.
-
-go-zero contains simple API description syntax and code generation tool called `goctl`. You can generate Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript from .api files with `goctl`.
-
-#### Advantages of go-zero:
-
-* Improves the stability of the services with tens of millions of daily active users
-* Builtin chained timeout control, concurrency control, rate limit, adaptive circuit breaker, adaptive load shedding, even no configuration needed
-* Builtin middlewares also can be integrated into your frameworks
-* Simple API syntax, one command to generate a couple of different languages
-* Auto validate the request parameters from clients
-* Plenty of builtin microservice management and concurrent toolkits
-
-<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/architecture-en.png" alt="Architecture" width="1500" />
-
-## Backgrounds of go-zero
-
-At the beginning of 2018, we decided to re-design our system, from monolithic architecture with Java+MongoDB to microservice architecture. After research and comparison, we chose to:
-In early 2018, we embarked on a transformative journey to redesign our system, transitioning from a monolithic architecture built with Java and MongoDB to a microservices architecture. After careful research and comparison, we made a deliberate choice to:
-
-* Go Beyond with Golang
-  * Great performance
-  * Simple syntax
-  * Proven engineering efficiency
-  * Extreme deployment experience
-  * Less server resource consumption
-
-* Self-Design Our Microservice Architecture
-  * Microservice architecture facilitates the creation of scalable, flexible, and maintainable software systems with independent, reusable components.
-  * Easy to locate the problems within microservices.
-  * Easy to extend the features by adding or modifying specific microservices without impacting the entire system.
-
-## Design considerations on go-zero
-
-By designing the microservice architecture, we expected to ensure stability, as well as productivity. And from just the beginning, we have the following design principles:
-
-* Keep it simple
-* High availability
-* Stable on high concurrency
-* Easy to extend
-* Resilience design, failure-oriented programming
-* Try best to be friendly to the business logic development, encapsulate the complexity
-* One thing, one way
-
-After almost half a year, we finished the transfer from a monolithic system to microservice system and deployed on August 2018. The new system guaranteed business growth and system stability.
-
-## The implementation and features of go-zero
-
-go-zero is a web and rpc framework that integrates lots of engineering practices. The features are mainly listed below:
-
-* Powerful tool included, less code to write
-* Simple interfaces
-* Fully compatible with net/http
-* Middlewares are supported, easy to extend
-* High performance
-* Failure-oriented programming, resilience design
-* Builtin service discovery, load balancing
-* Builtin concurrency control, adaptive circuit breaker, adaptive load shedding, auto-trigger, auto recover
-* Auto validation of API request parameters
-* Chained timeout control
-* Auto management of data caching
-* Call tracing, metrics, and monitoring
-* High concurrency protected
-
-As below, go-zero protects the system with a couple of layers and mechanisms:
-
-![Resilience](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/resilience-en.png)
-
-##  The simplified architecture that we use with go-zero
-
-<img width="1067" alt="image" src="https://user-images.githubusercontent.com/1918356/171880372-5010d846-e8b1-4942-8fe2-e2bbb584f762.png">
-
-##  Installation
-
-Run the following command under your project:
-
-```shell
-go get -u github.com/zeromicro/go-zero
-```
-
-##  Quick Start
-
-1. Full examples can be checked out from below:
-
-     [Rapid development of microservice systems](https://github.com/zeromicro/zero-doc/blob/main/doc/shorturl-en.md)
-
-     [Rapid development of microservice systems - multiple RPCs](https://github.com/zeromicro/zero-doc/blob/main/docs/zero/bookstore-en.md)
-
-2. Install goctl
-
-   `goctl`can be read as `go control`. `goctl` means not to be controlled by code, instead, we control it. The inside `go` is not `golang`. At the very beginning, I was expecting it to help us improve productivity, and make our lives easier.
-
-   ```shell
-   # for Go
-   go install github.com/zeromicro/go-zero/tools/goctl@latest
-   
-   # For Mac
-   brew install goctl
-   
-   # docker for amd64 architecture
-   docker pull kevinwan/goctl
-   # run goctl like
-   docker run --rm -it -v `pwd`:/app kevinwan/goctl goctl --help
-   
-   # docker for arm64(Mac) architecture
-   docker pull kevinwan/goctl:latest-arm64
-   # run goctl like
-   docker run --rm -it -v `pwd`:/app kevinwan/goctl:latest-arm64 goctl --help
-   ```
-   
-   make sure goctl is executable.
-   
-3. Create the API file, like greet.api, you can install the plugin of goctl in vs code, api syntax is supported.
-
-   ```go
-   type (
-     Request {
-       Name string `path:"name,options=[you,me]"` // parameters are auto validated
-     }
-
-     Response {
-       Message string `json:"message"`
-     }
-   )
-
-   service greet-api {
-     @handler GreetHandler
-     get /greet/from/:name(Request) returns (Response)
-   }
-   ```
-
-   the .api files also can be generated by goctl, like below:
-
-   ```shell
-   goctl api -o greet.api
-   ```
-
-4. Generate the go server-side code
-
-   ```shell
-   goctl api go -api greet.api -dir greet
-   ```
-
-   the generated files look like:
-
-   ```Plain Text
-   ├── greet
-   │   ├── etc
-   │   │   └── greet-api.yaml        // configuration file
-   │   ├── greet.go                  // main file
-   │   └── internal
-   │       ├── config
-   │       │   └── config.go         // configuration definition
-   │       ├── handler
-   │       │   ├── greethandler.go   // get/put/post/delete routes are defined here
-   │       │   └── routes.go         // routes list
-   │       ├── logic
-   │       │   └── greetlogic.go     // request logic can be written here
-   │       ├── svc
-   │       │   └── servicecontext.go // service context, mysql/redis can be passed in here
-   │       └── types
-   │           └── types.go          // request/response defined here
-   └── greet.api                     // api description file
-   ```
-
-   the generated code can be run directly:
-
-   ```shell
-   cd greet
-   go mod init
-   go mod tidy
-   go run greet.go -f etc/greet-api.yaml
-   ```
-
-   by default, it’s listening on port 8888, while it can be changed in the configuration file.
-
-   you can check it by curl:
-
-   ```shell
-   curl -i http://localhost:8888/greet/from/you
-   ```
-
-   the response looks like below:
-
-   ```http
-   HTTP/1.1 200 OK
-   Date: Sun, 30 Aug 2020 15:32:35 GMT
-   Content-Length: 0
-   ```
-
-5. Write the business logic code
-
-    * the dependencies can be passed into the logic within servicecontext.go, like mysql, redis, etc.
-    * add the logic code in a logic package according to .api file
-
-6. Generate code like Java, TypeScript, Dart, JavaScript, etc. just from the api file
-
-   ```shell
-   goctl api java -api greet.api -dir greet
-   goctl api dart -api greet.api -dir greet
-   ...
-   ```
-
-## Benchmark
-
-![benchmark](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/benchmark.png)
-
-[Checkout the test code](https://github.com/smallnest/go-web-framework-benchmark)
-
-## Documents
-
-* [Documents](https://go-zero.dev/)
-* [Rapid development of microservice systems](https://github.com/zeromicro/zero-doc/blob/main/doc/shorturl-en.md)
-* [Rapid development of microservice systems - multiple RPCs](https://github.com/zeromicro/zero-doc/blob/main/docs/zero/bookstore-en.md)
-* [Examples](https://github.com/zeromicro/zero-examples)
-
-##  Chat group
-
-Join the chat via https://discord.gg/4JQvC5A4Fe
-
-##  Cloud Native Landscape
-
-<p float="left">
-<img src="https://landscape.cncf.io/images/left-logo.svg" width="150"/>&nbsp;&nbsp;&nbsp;
-<img src="https://landscape.cncf.io/images/right-logo.svg" width="200"/>
-</p>
-
-go-zero enlisted in the [CNCF Cloud Native Landscape](https://landscape.cncf.io/?selected=go-zero).
-
-## Give a Star! ⭐
-
-If you like or are using this project to learn or start your solution, please give it a star. Thanks!
-
-## Buy me a coffee
-
-<a href="https://www.buymeacoffee.com/kevwan" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
+# go-zero-wt
+## 简介
+开源项目go-zero的桓创适配版本  
+新增若干功能  
+
+## 开源项目
+[go-zero](https://github.com/zeromicro/go-zero)  
+[go-zero-superh](https://github.com/SuperH-0630/go-zero)  

+ 4 - 0
rest/httpx/router.go

@@ -2,10 +2,14 @@ package httpx
 
 import "net/http"
 
+type MiddlewareFunc func(http.Handler) http.Handler
+
 // Router interface represents a http router that handles http requests.
 type Router interface {
 	http.Handler
 	Handle(method, path string, handler http.Handler) error
 	SetNotFoundHandler(handler http.Handler)
 	SetNotAllowedHandler(handler http.Handler)
+	SetOptionsHandler(handler http.Handler)
+	SetMiddleware(middleware MiddlewareFunc)
 }

+ 35 - 3
rest/router/patrouter.go

@@ -24,9 +24,11 @@ var (
 )
 
 type patRouter struct {
-	trees      map[string]*search.Tree
-	notFound   http.Handler
-	notAllowed http.Handler
+	trees         map[string]*search.Tree
+	notFound      http.Handler
+	notAllowed    http.Handler
+	optionsHandle http.Handler
+	middleware    httpx.MiddlewareFunc
 }
 
 // NewRouter returns a httpx.Router.
@@ -57,6 +59,19 @@ func (pr *patRouter) Handle(method, reqPath string, handler http.Handler) error
 }
 
 func (pr *patRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+	if pr.middleware != nil {
+		pr.middleware(http.HandlerFunc(pr.serveHTTP)).ServeHTTP(w, r)
+	} else {
+		pr.serveHTTP(w, r)
+	}
+}
+
+func (pr *patRouter) serveHTTP(w http.ResponseWriter, r *http.Request) {
+	if r.Method == http.MethodOptions && pr.optionsHandle != nil {
+		pr.optionsHandle.ServeHTTP(w, r)
+		return
+	}
+
 	reqPath := path.Clean(r.URL.Path)
 	if tree, ok := pr.trees[r.Method]; ok {
 		if result, ok := tree.Search(reqPath); ok {
@@ -90,6 +105,23 @@ func (pr *patRouter) SetNotAllowedHandler(handler http.Handler) {
 	pr.notAllowed = handler
 }
 
+func (pr *patRouter) SetOptionsHandler(handler http.Handler) {
+	f := func(w http.ResponseWriter, r *http.Request) {
+		if r.Method != http.MethodOptions {
+			pr.notAllowed.ServeHTTP(w, r)
+			return
+		}
+
+		handler.ServeHTTP(w, r)
+	}
+
+	pr.optionsHandle = http.HandlerFunc(f)
+}
+
+func (pr *patRouter) SetMiddleware(middleware httpx.MiddlewareFunc) {
+	pr.middleware = middleware
+}
+
 func (pr *patRouter) handleNotFound(w http.ResponseWriter, r *http.Request) {
 	if pr.notFound != nil {
 		pr.notFound.ServeHTTP(w, r)