Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8be0615
Added go server
priankakariat Oct 4, 2024
4be4456
Added readme for go server
priankakariat Oct 4, 2024
95b2d7e
Fixed documentation and read me of go files
priankakariat Oct 4, 2024
a7bc461
Updated readme for go server
priankakariat Oct 4, 2024
0231060
Updated documentation of json.go
priankakariat Oct 4, 2024
bb41cba
Updated formatting of license in go files
priankakariat Oct 4, 2024
233135c
Added cors middleware handler to go server
priankakariat Oct 4, 2024
c2ffef4
Fixed readme for go server
priankakariat Oct 4, 2024
c0b4793
Update README.md
priankakariat Oct 4, 2024
e6ae3ac
Update README.md
priankakariat Oct 4, 2024
b6e7341
Update README.md to skip to manual install for Go
priankakariat Oct 4, 2024
6b4c610
Update README.md
priankakariat Oct 4, 2024
f8cb2af
Update README.md
priankakariat Oct 4, 2024
a4d7518
Update README.md
priankakariat Oct 4, 2024
f2328a4
Update README.md
priankakariat Oct 4, 2024
9e82320
Update README.md
priankakariat Oct 4, 2024
9e383b5
Update README.md
priankakariat Oct 4, 2024
873f294
Update README.md
priankakariat Oct 4, 2024
7f68b8d
Update README.md
priankakariat Oct 4, 2024
7235a45
Update README.md
priankakariat Oct 4, 2024
61dbb0f
Update README.md
priankakariat Oct 4, 2024
af01e1f
Update README.md
priankakariat Oct 4, 2024
54e4b23
Update README.md
priankakariat Oct 4, 2024
46a2d48
Updated documentation of main.go
priankakariat Oct 4, 2024
5c5a7fd
Merge branch 'server-go' of https://github.com/priankakariatyml/examp…
priankakariat Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated documentation of json.go
  • Loading branch information
priankakariat committed Oct 4, 2024
commit 0231060fd601bf154348101c1f15b1c6d8b33331
21 changes: 21 additions & 0 deletions server-go/json.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
Expand All @@ -7,6 +24,9 @@ import (
"net/http"
)

// parseRequestJSON populates the target with the fields of the JSON-encoded value in the request
// body. It expects the request to have the Content-Type header set to JSON and a body with a
// JSON-encoded value complying with the underlying type of target.
func parseRequestJSON(r *http.Request, target any) error {
contentType := r.Header.Get("Content-Type")
mediaType, _, err := mime.ParseMediaType(contentType)
Expand All @@ -23,6 +43,7 @@ func parseRequestJSON(r *http.Request, target any) error {
return dec.Decode(target)
}

// renderResponseJSON encodes res as JSON and writes it to w.
func renderResponseJSON(w http.ResponseWriter, res any) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(res)
Expand Down
17 changes: 17 additions & 0 deletions server-go/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* @license
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
Expand Down