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