emptygif
Ngôn ngữ: Tiếng Việt

Tất cả ngôn ngữ và framework

veb (V web framework) V

Đoạn mã V cho veb (V web framework), trả lời các yêu cầu tới /pixel.gif bằng GIF rỗng, được giải mã một lần khi khởi động.

veb (V web framework) V

Tệp
server.v
Chạy
v run server.v
module main

import encoding.base64
import veb

const gif = base64.decode_str('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')

pub struct Context {
    veb.Context
}

pub struct App {}

@['/pixel.gif'; get]
pub fn (app &App) pixel(mut ctx Context) veb.Result {
    ctx.set_header(.cache_control, 'no-store')
    return ctx.send_response_to_client('image/gif', gif)
}

fn main() {
    mut app := &App{}
    veb.run[App, Context](mut app, 8080)
}

Đã đối chiếu với tài liệu hiện hành của framework.

Kiểm tra

curl -sI http://localhost:8080/pixel.gif

Trang chính thức: veb (V web framework)