syntax = "v1" info ( title: "Short URL Gateway" desc: "Service for generating, retrieving, and deleting short URLs" author: "Daniel Wang" email: "igs170911@gmail.com" version: "0.0.1" ) type RespOK {} type CreateShortURLRequest { URL string `json:"url" validate:"required"` } type URLRequest { ShortCode string `path:"short_code"` } type Status { Code int64 `json:"code"` // 狀態碼 Message string `json:"message"` // 訊息 Data interface{} `json:"data,omitempty"` // 可選的資料,當有返回時才出現 Error interface{} `json:"error,omitempty"` // 可選的錯誤信息 } type URLResponse { URL string `json:"url" validate:"required"` } type URLCodeResponse { Code string `json:"short_code"` } @server ( group: url prefix: /api/v1/url schemes: https timeout: 10s ) service url { /* @respdoc-400 (BaseResponse) // Invalid input parameters */ /* @respdoc-500 (BaseResponse) // Server error */ @doc ( summary: "Create Short URL" description: "Map a long URL to a short URL" ) @handler createShortURL post / (CreateShortURLRequest) returns (URLCodeResponse) /* @respdoc-400 (BaseResponse) // Invalid input parameters */ /* @respdoc-500 (BaseResponse) // Server error */ @doc ( summary: "Retrieve Short URL" description: "Retrieve the original URL using the short URL" ) @handler getOriginalURL get /:short_code (URLRequest) returns (URLResponse) /* @respdoc-400 (BaseResponse) // Invalid input parameters */ /* @respdoc-500 (BaseResponse) // Server error */ @doc ( summary: "Delete Short URL" description: "Delete a short URL mapping" ) @handler deleteShortURL delete /:short_code (URLRequest) returns (RespOK) }