Skip to content

Commit 4f24b71

Browse files
committed
Format
1 parent 46fb787 commit 4f24b71

5 files changed

Lines changed: 161 additions & 102 deletions

File tree

examples/temperature_server/src/temperature_server.gleam

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ fn log_service_error(error: ServiceError) -> Nil {
4646
// Here you could emit metrics, send to logging service, etc.
4747
}
4848
proto.HandlerError(handler_error) -> {
49-
io.println(
50-
"[ERROR] Handler error: " <> string.inspect(handler_error),
51-
)
49+
io.println("[ERROR] Handler error: " <> string.inspect(handler_error))
5250
// Here you could emit metrics, track error rates, etc.
5351
}
5452
}

src/protozoa/internal/codegen.gleam

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,10 @@ fn has_float_query_params(proto_file: ProtoFile) -> Bool {
434434
|> list.any(fn(field) {
435435
case field.field_type {
436436
parser.Float | parser.Double -> True
437-
parser.Repeated(parser.Float) | parser.Repeated(parser.Double) -> True
438-
parser.Optional(parser.Float) | parser.Optional(parser.Double) -> True
437+
parser.Repeated(parser.Float) | parser.Repeated(parser.Double) ->
438+
True
439+
parser.Optional(parser.Float) | parser.Optional(parser.Double) ->
440+
True
439441
_ -> False
440442
}
441443
})

src/protozoa/internal/codegen/router.gleam

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ pub fn generate_service_router(
5252
// Generate Layer 2: HTTP adapter functions (gleam/http types)
5353
let http_adapters =
5454
list.filter(methods, has_http_annotation)
55-
|> list.map(fn(method) {
56-
generate_http_adapter(method, service.name)
57-
})
55+
|> list.map(fn(method) { generate_http_adapter(method, service.name) })
5856
|> string.join("\n\n")
5957

6058
// Generate error types and converters
@@ -118,9 +116,7 @@ fn generate_service_function(method: Method, service_name: String) -> String {
118116
[
119117
"/// Service function for " <> method.name,
120118
"/// Handles protobuf encoding/decoding, returns encoded response or error",
121-
"pub fn "
122-
<> function_name
123-
<> "(",
119+
"pub fn " <> function_name <> "(",
124120
" request_bytes: BitArray,",
125121
" handler: fn("
126122
<> request_type
@@ -177,9 +173,7 @@ fn generate_http_adapter(method: Method, service_name: String) -> String {
177173
string.join(
178174
[
179175
" let request_bytes = req.body",
180-
" case "
181-
<> service_function_name
182-
<> "(request_bytes, handler) {",
176+
" case " <> service_function_name <> "(request_bytes, handler) {",
183177
" Ok(response_bytes) -> {",
184178
" response.Response(",
185179
" status: 200,",
@@ -240,9 +234,7 @@ fn generate_http_adapter(method: Method, service_name: String) -> String {
240234
"/// HTTP adapter for " <> method.name,
241235
"/// " <> http_method_str <> " " <> path,
242236
"/// Uses gleam/http types (server-agnostic)",
243-
"pub fn "
244-
<> function_name
245-
<> "(",
237+
"pub fn " <> function_name <> "(",
246238
" req: request.Request(BitArray),",
247239
" handler: fn("
248240
<> request_type
@@ -737,19 +729,20 @@ fn analyze_needed_helpers(
737729
messages: List(Message),
738730
) -> NeededHelpers {
739731
// Start with all helpers disabled
740-
let initial = NeededHelpers(
741-
path_extraction: False,
742-
path_string: False,
743-
path_int: False,
744-
query_string: False,
745-
query_int: False,
746-
query_bool: False,
747-
query_float: False,
748-
query_list_string: False,
749-
query_list_int: False,
750-
query_optional_string: False,
751-
query_optional_int: False,
752-
)
732+
let initial =
733+
NeededHelpers(
734+
path_extraction: False,
735+
path_string: False,
736+
path_int: False,
737+
query_string: False,
738+
query_int: False,
739+
query_bool: False,
740+
query_float: False,
741+
query_list_string: False,
742+
query_list_int: False,
743+
query_optional_string: False,
744+
query_optional_int: False,
745+
)
753746

754747
// Analyze each method that uses GET/DELETE (query/path params)
755748
list.fold(service.methods, initial, fn(acc, method) {
@@ -768,12 +761,18 @@ fn analyze_needed_helpers(
768761
// Analyze each field
769762
list.fold(message.fields, acc, fn(field_acc, field) {
770763
let field_name_lower = string.lowercase(field.name)
771-
let is_path_param = list.any(path_params, fn(param) {
772-
string.lowercase(param) == field_name_lower
773-
})
764+
let is_path_param =
765+
list.any(path_params, fn(param) {
766+
string.lowercase(param) == field_name_lower
767+
})
774768

775769
case is_path_param {
776-
True -> analyze_path_param_type(field.field_type, field_acc, has_path_params)
770+
True ->
771+
analyze_path_param_type(
772+
field.field_type,
773+
field_acc,
774+
has_path_params,
775+
)
777776
False -> analyze_query_param_type(field.field_type, field_acc)
778777
}
779778
})
@@ -1355,4 +1354,3 @@ fn generate_query_param_helpers() -> String {
13551354
"\n",
13561355
)
13571356
}
1358-

src/protozoa/internal/well_known_types.gleam

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ fn annotations_proto() -> parser.ProtoFile {
414414
parser.ProtoFile(
415415
syntax: "proto3",
416416
package: option.Some("google.api"),
417-
imports: [parser.Import(path: "google/api/http.proto", public: False, weak: False)],
417+
imports: [
418+
parser.Import(path: "google/api/http.proto", public: False, weak: False),
419+
],
418420
messages: [],
419421
enums: [],
420422
services: [],

0 commit comments

Comments
 (0)