Nginx Module Development-nginx Code specification

Source: Internet
Author: User

1, Introduction

Basically, Nginx The use of a similar BSD of the C code style, very normative, but also very clear. It is suggested that our nginx Module Development also adopts nginx coding style.

2, naming methods

letters are lowercase except for macro definitions, with underscores between words (_) interval.

3, Alignment

The code Way is K&r alignment, you need to be aware of the following points:

( 1 ) with a space instead of Tab alignment, the number of spaces is 4 a ;

if (ngx_process = = Ngx_process_single) {

Ngx_single_process_cycle (cycle);

} else {

Ngx_master_process_cycle (cycle);

}

( 2 ) empty two lines between the block and the function;

( 3 ) The variable Declaration is aligned up and down ;

( 4 ) function declarations are all written in one line;

Static ngx_int_t Ngx_http_tfs_status_message (ngx_buf_t *b, ngx_str_t *action, ngx_log_t *log);

( 5 The function definition takes the following method to divide the return value and function name into 2 line to write;

Static ngx_chain_t *
Ngx_tfs_message_ds_create_write_packet (ngx_http_tfs_t *t)
That is, the return value and function name are divided into two lines to write.

( 6 ) functions and functions must be separated by two lines of line breaks.

Static ngx_chain_t * Ngx_tfs_ms_create_read_packet (ngx_http_tfs_t *t) {}

Static ngx_chain_t * Ngx_tfs_ms_create_write_packet (ngx_http_tfs_t *t)

(7) forLooping format: there should be a space between the variable and the semicolon, followed by curly braces and foron one line. ifthe format and forsimilar.  all theifmust have parentheses and cannot omit curly braces.

for (i = 0; i < ds->count; i++) {

..............

}

4, annotation method

C style annotations, such as: / * Comment * /

5, copyright information

At the beginning of the file, sign an empty line, followed by two empty lines, such as

/*
* Copyright (C) Igor Sysoev
*/


Nginx Module Development-nginx Code specification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.