From 611db65e644791dce60029553e11676d9c1f98e9 Mon Sep 17 00:00:00 2001 From: Adam Bouqdib Date: Tue, 10 Jan 2023 23:07:21 +0000 Subject: [PATCH 1/6] feat: add header case --- tagliatelle.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tagliatelle.go b/tagliatelle.go index 53e77d1..b2a7848 100644 --- a/tagliatelle.go +++ b/tagliatelle.go @@ -200,6 +200,8 @@ func getConverter(c string) (func(s string) string, error) { return strcase.ToGoKebab, nil case "goSnake": return strcase.ToGoSnake, nil + case "header": + return func(s string) string { return strcase.ToCase(s, strcase.TitleCase, '-') }, nil case "upper": return strings.ToUpper, nil case "lower": From fefc6e63f39220b5cb08dbb767f912d9f8a1315c Mon Sep 17 00:00:00 2001 From: Adam Bouqdib Date: Tue, 10 Jan 2023 23:14:33 +0000 Subject: [PATCH 2/6] docs: update readme --- readme.md | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/readme.md b/readme.md index f58f9ee..753c7f5 100644 --- a/readme.md +++ b/readme.md @@ -15,11 +15,12 @@ Supported string casing: - `goPascal` Respects [Go's common initialisms](https://github.com/golang/lint/blob/83fdc39ff7b56453e3793356bcff3070b9b96445/lint.go#L770-L809) (e.g. HttpResponse -> HTTPResponse). - `goKebab` Respects [Go's common initialisms](https://github.com/golang/lint/blob/83fdc39ff7b56453e3793356bcff3070b9b96445/lint.go#L770-L809) (e.g. HttpResponse -> HTTPResponse). - `goSnake` Respects [Go's common initialisms](https://github.com/golang/lint/blob/83fdc39ff7b56453e3793356bcff3070b9b96445/lint.go#L770-L809) (e.g. HttpResponse -> HTTPResponse). +- `header` - `upper` - `lower` | Source | Camel Case | Go Camel Case | -|----------------|----------------|----------------| +| -------------- | -------------- | -------------- | | GooID | gooId | gooID | | HTTPStatusCode | httpStatusCode | httpStatusCode | | FooBAR | fooBar | fooBar | @@ -32,7 +33,7 @@ Supported string casing: | UneTête | uneTête | uneTête | | Source | Pascal Case | Go Pascal Case | -|----------------|----------------|----------------| +| -------------- | -------------- | -------------- | | GooID | GooId | GooID | | HTTPStatusCode | HttpStatusCode | HTTPStatusCode | | FooBAR | FooBar | FooBar | @@ -45,7 +46,7 @@ Supported string casing: | UneTête | UneTête | UneTête | | Source | Snake Case | Go Snake Case | -|----------------|------------------|------------------| +| -------------- | ---------------- | ---------------- | | GooID | goo_id | goo_ID | | HTTPStatusCode | http_status_code | HTTP_status_code | | FooBAR | foo_bar | foo_bar | @@ -57,18 +58,18 @@ Supported string casing: | NameJSON | name_json | name_JSON | | UneTête | une_tête | une_tête | -| Source | Kebab Case | Go KebabCase | -|----------------|------------------|------------------| -| GooID | goo-id | goo-ID | -| HTTPStatusCode | http-status-code | HTTP-status-code | -| FooBAR | foo-bar | foo-bar | -| URL | url | URL | -| ID | id | ID | -| hostIP | host-ip | host-IP | -| JSON | json | JSON | -| JSONName | json-name | JSON-name | -| NameJSON | name-json | name-JSON | -| UneTête | une-tête | une-tête | +| Source | Kebab Case | Go KebabCase | Header Case | +| -------------- | ---------------- | ---------------- | ---------------- | +| GooID | goo-id | goo-ID | Goo-Id | +| HTTPStatusCode | http-status-code | HTTP-status-code | Http-Status-Code | +| FooBAR | foo-bar | foo-bar | Foo-Bar | +| URL | url | URL | Url | +| ID | id | ID | Id | +| hostIP | host-ip | host-IP | Host-Ip | +| JSON | json | JSON | Json | +| JSONName | json-name | JSON-name | Json-Name | +| NameJSON | name-json | name-JSON | Name-Json | +| UneTête | une-tête | une-tête | Une-Tête | ## Examples @@ -130,7 +131,7 @@ Here are the default rules for the well known and used tags, when using tagliate - `json`: `camel` - `yaml`: `camel` -- `xml`: `camel` +- `xml` : `camel` - `bson`: `camel` - `avro`: `snake` From ac10e73b39554c1a2d37f5eb5778bd1e8b3b0740 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 11 Jan 2023 00:21:05 +0100 Subject: [PATCH 3/6] review --- readme.md | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/readme.md b/readme.md index 753c7f5..67e6efa 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,7 @@ Supported string casing: - `lower` | Source | Camel Case | Go Camel Case | -| -------------- | -------------- | -------------- | +|----------------|----------------|----------------| | GooID | gooId | gooID | | HTTPStatusCode | httpStatusCode | httpStatusCode | | FooBAR | fooBar | fooBar | @@ -33,7 +33,7 @@ Supported string casing: | UneTête | uneTête | uneTête | | Source | Pascal Case | Go Pascal Case | -| -------------- | -------------- | -------------- | +|----------------|----------------|----------------| | GooID | GooId | GooID | | HTTPStatusCode | HttpStatusCode | HTTPStatusCode | | FooBAR | FooBar | FooBar | @@ -46,7 +46,7 @@ Supported string casing: | UneTête | UneTête | UneTête | | Source | Snake Case | Go Snake Case | -| -------------- | ---------------- | ---------------- | +|----------------|------------------|------------------| | GooID | goo_id | goo_ID | | HTTPStatusCode | http_status_code | HTTP_status_code | | FooBAR | foo_bar | foo_bar | @@ -58,18 +58,31 @@ Supported string casing: | NameJSON | name_json | name_JSON | | UneTête | une_tête | une_tête | -| Source | Kebab Case | Go KebabCase | Header Case | -| -------------- | ---------------- | ---------------- | ---------------- | -| GooID | goo-id | goo-ID | Goo-Id | -| HTTPStatusCode | http-status-code | HTTP-status-code | Http-Status-Code | -| FooBAR | foo-bar | foo-bar | Foo-Bar | -| URL | url | URL | Url | -| ID | id | ID | Id | -| hostIP | host-ip | host-IP | Host-Ip | -| JSON | json | JSON | Json | -| JSONName | json-name | JSON-name | Json-Name | -| NameJSON | name-json | name-JSON | Name-Json | -| UneTête | une-tête | une-tête | Une-Tête | +| Source | Kebab Case | Go KebabCase | +|----------------|------------------|------------------| +| GooID | goo-id | goo-ID | +| HTTPStatusCode | http-status-code | HTTP-status-code | +| FooBAR | foo-bar | foo-bar | +| URL | url | URL | +| ID | id | ID | +| hostIP | host-ip | host-IP | +| JSON | json | JSON | +| JSONName | json-name | JSON-name | +| NameJSON | name-json | name-JSON | +| UneTête | une-tête | une-tête | + +| Source | Header Case | +|----------------|------------------| +| GooID | Goo-Id | +| HTTPStatusCode | Http-Status-Code | +| FooBAR | Foo-Bar | +| URL | Url | +| ID | Id | +| hostIP | Host-Ip | +| JSON | Json | +| JSONName | Json-Name | +| NameJSON | Name-Json | +| UneTête | Une-Tête | ## Examples @@ -131,7 +144,7 @@ Here are the default rules for the well known and used tags, when using tagliate - `json`: `camel` - `yaml`: `camel` -- `xml` : `camel` +- `xml`: `camel` - `bson`: `camel` - `avro`: `snake` From b6e35b8b1296030f2d790b13d6a79bbcddfa2554 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 11 Jan 2023 00:32:29 +0100 Subject: [PATCH 4/6] review --- cmd/tagliatelle/tagliatelle.go | 11 ++++++----- tagliatelle_test.go | 1 + testdata/src/a/sample.go | 12 +++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cmd/tagliatelle/tagliatelle.go b/cmd/tagliatelle/tagliatelle.go index b5acc18..3e35137 100644 --- a/cmd/tagliatelle/tagliatelle.go +++ b/cmd/tagliatelle/tagliatelle.go @@ -8,11 +8,12 @@ import ( func main() { cfg := tagliatelle.Config{ Rules: map[string]string{ - "json": "camel", - "yaml": "camel", - "xml": "camel", - "bson": "camel", - "avro": "snake", + "json": "camel", + "yaml": "camel", + "xml": "camel", + "bson": "camel", + "avro": "snake", + "header": "header", }, UseFieldName: true, } diff --git a/tagliatelle_test.go b/tagliatelle_test.go index 355cb41..7771a76 100644 --- a/tagliatelle_test.go +++ b/tagliatelle_test.go @@ -18,6 +18,7 @@ func TestAnalyzer(t *testing.T) { "bson": "camel", "avro": "snake", "mapstructure": "kebab", + "header": "header", }, UseFieldName: true, } diff --git a/testdata/src/a/sample.go b/testdata/src/a/sample.go index b35a499..358381d 100644 --- a/testdata/src/a/sample.go +++ b/testdata/src/a/sample.go @@ -25,11 +25,13 @@ type Bir struct { } type Bur struct { - Name string - Value string `yaml:"Value"` // want `yaml\(camel\): got 'Value' want 'value'` - More string `json:"-"` - Also string `json:",omitempty"` // want `json\(camel\): got 'Also' want 'also'` - ReqPerS string `avro:"req_per_s"` + Name string + Value string `yaml:"Value"` // want `yaml\(camel\): got 'Value' want 'value'` + More string `json:"-"` + Also string `json:",omitempty"` // want `json\(camel\): got 'Also' want 'also'` + ReqPerS string `avro:"req_per_s"` + HeaderValue string `header:"Header-Value"` + WrongHeaderValue string `header:"Header_Value"` // want `header\(header\): got 'Header_Value' want 'Wrong-Header-Value'` } type Quux struct { From 3d2eb196366e6bc6ddc2f29cb21c9b2c8b8d4d5e Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 11 Jan 2023 00:35:25 +0100 Subject: [PATCH 5/6] review --- tagliatelle.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tagliatelle.go b/tagliatelle.go index b2a7848..c465376 100644 --- a/tagliatelle.go +++ b/tagliatelle.go @@ -201,7 +201,7 @@ func getConverter(c string) (func(s string) string, error) { case "goSnake": return strcase.ToGoSnake, nil case "header": - return func(s string) string { return strcase.ToCase(s, strcase.TitleCase, '-') }, nil + return toHeader, nil case "upper": return strings.ToUpper, nil case "lower": @@ -210,3 +210,7 @@ func getConverter(c string) (func(s string) string, error) { return nil, fmt.Errorf("unsupported case: %s", c) } } + +func toHeader(s string) string { + return strcase.ToCase(s, strcase.TitleCase, '-') +} From 929791b4224b3d638375512a6619d6820e0b751f Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 11 Jan 2023 00:37:13 +0100 Subject: [PATCH 6/6] review --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 67e6efa..7bd728d 100644 --- a/readme.md +++ b/readme.md @@ -147,6 +147,7 @@ Here are the default rules for the well known and used tags, when using tagliate - `xml`: `camel` - `bson`: `camel` - `avro`: `snake` +- `header`: `header` ### Custom Rules