Is it possible to iterate through all the keys and values of a JSON object in Golang, identify a specific value based on a match with either the key or value, replace that value, and then create a new data structure with the updated value? I came across a ...
Currently using the Go and VueJS stack, but encountered an issue with SSR. The index.html is precompiled with GO to generate meta tags (using html/template) {{ range index . "metaTags" }} <meta {{.Key |safe }}='{{ .Name }}' {{ .Ty ...
Here is a struct I am working with: type ResponseStatus struct { StatusCode int Message string Data string `json:"data"` } type Pets struct { Id int `json:"id"` Name string `json:"name"` Age int `json:"age"` ...
I have encountered a situation where I need to manipulate JSON data by performing certain transformations and then send it by marshaling. However, my requirement is to change the variable name in the final marshaled JSON. Is it possible to marshal the dat ...
struct Alpha { Label text `json:"label"` ExcludeDuringSerialization string `json:"excludeDuringSerialization"` } func SerializeJSON(obj interface{}){ json.Serialize(obj) } How can I exclude the ExcludeDuringSerializa ...
Good morning, I have a Go code that processes a JSON post request and performs certain actions. However, I am looking to send back either the result or a message to jQuery. package main import ( "fmt" "log" "net/http" "encoding/json" ...
I recently started using the Go selenium package available at this link Currently, I have set up a headless chrome + selenium-server configuration within a docker container on localhost:4444 The server appears to be running smoothly as I am able to acces ...
Just starting out with Go and I'm having trouble fetching and marshalling json data into a struct. The data format I'm working with is as follows: var reducedFieldData = []byte(`[ {"model":"Traverse","vin":"1gnkrhkd6ej111234"}, {"model":"TL","vin" ...
I have an HTML file named email.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Shareholder</title> </head> <body> <h1> {{.PageTitle}} </h1> ...
Just starting out in Go Lang and looking to parse a JSON structure like the one below to extract all objects in the records array. [ { "records": [ {"name":"value"},{"name":"value"} ] }, { "records": [ ...
package main import ( "fmt" "time" "github.com/tebeka/selenium" "github.com/tebeka/selenium/chrome" ) func main() { // Launch Chrome browser service, err := selenium.NewChromeDriverService("./chromedriver", 4444) if err ...
After finding a JSON file named sample.json, I discovered that it contains an array of JSON objects with timestamps, extra data IDs, and event information. Here's a snippet: [ { "time": "2021-01-04T00:11:32.362Z", "extra_data": { "id": "123" }, ...
I have a struct: type ProductConstructed struct { Name string `json:"Name"` BrandMedals []string `json:"BRAND_MEDALS"` } When I use gin to return my object: func constructProduct(c *gin.Context) { var response ProductConst ...
In my program, I utilize a JSON file to set up the arguments and also use the flag package to configure the same arguments. Whenever an argument is parsed by both the JSON file and the flag at the same time, I prefer to use the argument parsed through the ...
Recently, I have been working on developing a REST API using Sails.js. As I outlined the resources needed for my application, it struck me that many frameworks (based on Express) are proficient at handling single resources. However, in most cases, I found ...
After following a guide to serve a NextJs front-end single-page application using Golang and the native net/http package, I decided to switch to using gorilla/mux. Here is my updated main function: func main() { // Root at the `dist` folder generated ...
I've recently been experimenting with this Go-based forum software that comes with a configuration file requiring specific values as outlined in the main.go file below. Initially, I attempted using an empty string "" for the oauth credentials while testing ...
I am currently working on implementing Google OAuth2 in my Go web server using Gin. I have integrated two new endpoints - /google/sign-in and /google/callback. The former receives the request and redirects to the Google auth URL, while the latter is trigge ...
Utilizing the http module, I have a request from the Front-End developers team to return an empty list and status code 204 when there are no search results. Here is my attempt: AllPosts := logic.MergedSearchSearchPost(params) if len(AllPosts.Posts) == 0 { ...
I have the need to transfer a MongoDB query to a different system and I would like to utilize the MongoDB Extended JSON for this purpose, especially because my queries involve date comparisons. The main issue at hand is transferring a MongoDB query genera ...
Just starting out with golang here. I'm looking to decode some JSON data as shown below: { "intro": { "title": "The Little Blue Gopher", "story": [ "Once upon a time, long long ago, there was a little blue gopher. Our little blue fr ...
As a newcomer to Golang, I seek forgiveness for my lack of knowledge and potential incorrect approach. Currently, I am working on developing a Terraform provider for an internal service. This involves unmarshalling JSON data into pre-defined Struct Types ...
I currently have a structured data with a JSON field that looks like this: data := &Data{ Title string Content json.RawMessage } The template for this data is as follows: template = For {{Title}} - created at: {{CreatedAt}} / updated at: {{Updated ...
Is there a way to utilize .Decode() on a response body to populate a struct without needing to determine the specific type of struct beforehand? I have a versatile struct called Match, designed to store information about various games, like a match in For ...
My architecture consists of a NextJS frontend and Golang backend with an authentication system using JWTs and an internal user/password database. I am now looking to add OAuth sign-in alongside the current JWT system, while still maintaining API calls with ...
Is it true that non-blocking web servers like node.js, eventmachine, and tornado can become unresponsive if they encounter a blocking library? Does the same hold true for Golang? If one goroutine becomes blocked, will another automatically be allocated C ...
Problem Description The issue I am facing is that Go Code is not displaying the posted JSON value from jQuery AJAX. Main Go Code routing := chi.NewRouter() routing.Post("/authenticate", AuthenticateRouter) Go Code Snippet func AuthenticateRouter(w http. ...
Hello, currently I am using Golang for encoding/json and encountering an issue where the JSON error is returning as null: {"user_message":"Can't find any Query with those parameters","application_context":"GroupsRepository.GetGroupsByQuery: Applicati ...
When working with nested JSON in Go, I often find myself wondering about the most correct or idiomatic way to create the struct it's parsed into. Single struct: type myStruct struct { Fields struct { Struct0 struct { Field0 string ...
Can you help me understand why golang unmarshalling is returning a nil result for one decoding attempt of a JSON array, but successful in another? I'm confused about what could be causing this difference. Is it a mistake in the code or is it expected behav ...
I am relatively new to Go and I find myself regularly receiving a small (~1KB) JSON file from an API that acts as a log. My goal is to preserve each of these files for future reference. Instead of using a database, which seems unnecessary for this task, I ...
I am in the process of developing a Single Page Application using Angular 2 and Go. When it comes to routing in Angular, I have encountered an issue. For example, if I visit http://example.com/, Go serves me the index.html file as intended with this code: ...
I have successfully implemented user authentication on my website using Node.js and Passport. However, I am now looking to migrate to Golang and need to figure out how to authenticate users using the passwords stored in the database. The encryption code ...
I am currently developing a custom terraform provider and have encountered an issue. I'm attempting to convert a schema.TypeList field into a struct. Here is what the TypeList looks like: "template": { Type: schema.TypeLi ...
encoder := json.NewEncoder(writer) error := encoder.Encode(struct { RequestMethod string `json:"request_method"` QueryResults []interface{} `json:"query_results"` TimeInCache int `json:"time_in_cache"` }{RequestMethod: pro ...
Just starting out with Beego and attempting to generate a JSON response on a specific route. Below is how my controller is set up: package controllers import ( "github.com/astaxie/beego" ) type ErrorController struct { beego.Controller } type ...
Is it possible to Marshal/Unmarshal a struct in Go? type MyType struct { Items <What should be included here?> `json:"item"` } An example JSON document that needs to be handled is {"items":["value1", {"x":"y"}, "value3"]} I am new to Go ...
Utilizing the go-jmespath Golang library for querying a json file, my code is structured as follows: package main import ( "encoding/json" "log" "github.com/jmespath/go-jmespath" ) func main() { var jsonBlob = []byte(`[ { "o ...
I've been tasked with creating a basic RESTful service in Go that retrieves data for a specific book based on its ID. type Book struct { ID string `json:"id"` Isbn string `json:"isbn"` Title string `json:"title"` Author *Author ` ...
My current code successfully handles JSON in the body of a POST request, but I am now looking to switch to using form-data instead. This is my existing code: func Signin(c *fiber.Ctx) error { var data map[string]string if err := c.BodyParser(& ...
I encountered an issue with struct A and B while unmarshalling JSON strings. When a JSON string meant for struct A is unmarshalled correctly, it works fine. However, if the same JSON string is mistakenly unmarshalled into struct B, it still succeeds (which ...
I am attempting to utilize a library installed via npm in the Go template. By running 'npm install three', I have successfully installed the required three libraries, which are saved in the root folder as depicted in the provided screenshot below. https: ...
When it comes to the naming convention of variables in a database, it is customary to use full_name. However, in Postman, the convention dictates using fullName instead. type Person struct { FullName string `json:"fullName"` } Nevertheless, ...
In my programming practice, I have a preference for using pointers with primitive data types in my structs. By doing so, I ensure that when I use json.Marshal to convert them, any nil fields are represented as "field": null in the resulting JSON string. Ho ...
Looking to implement the readUint16BE function in node.js, here's how it is declared: buf.readUInt16BE(offset, [noAssert]) Documentation: http://nodejs.org/api/buffer.html#buffer_buf_readuint16be_offset_noassert This function reads an unsigned 1 ...
I am looking to install a compiled Golang program so that I can run it with a bash command from any location on my computer. Is there an equivalent of the npm global installation for Golang? For example, in nodejs, we use "npm install -g express" to global ...
As a newcomer to Vuejs and golang, I encountered an issue when attempting to send an Authorization token through the header while making an API call from Vue Axios. The error message that was displayed is as follows: "Access to XMLHttpRequest at 'htt ...
I am currently in the process of converting a node service to Go. In order to do this, I require a compatible md5 hash generator (not for password storage!). However, I am experiencing different results in this scenario: When creating md5s in Node, the cr ...
I am currently exploring the process of transferring data between a lightweight Golang web server and a Vue.js frontend. This is the content of the server-gorillamux.go file: ... // Your original code here And this is the content of the /src/components/ ...
Currently, I am working on a nested structure in golang and trying to manage which substructures should be displayed in JSON. For example, if I only want to show the treeid and name fields from Citrus, I attempted the following notation, but it still prin ...
Can someone help me with a question regarding JSON unmarshalling? I am facing an issue where the type is lost after unmarshalling the data. Here's an example of what I'm experiencing: package main import ( "encoding/json" " ...
Dealing with an API that usually returns JSON string values but occasionally provides numbers instead can be tricky. For example, most of the time it looks like this: { "Description": "Doorknob", "Amount": "3.25&q ...
We are currently implementing the use of github actions, with a focus on securely storing sensitive information like kubeconfig within github's secrets. A GitHub secret has been set up under the name KUBECONFIG1 Steps to Replicate The GitHub secret shoul ...
This snippet of code is used to test the functionality of listing users in a web application. req := httptest.NewRequest("GET", "/v1/users", nil) resp := httptest.NewRecorder() u.app.ServeHTTP(resp, req) if resp.Code != http.StatusOK { ...
I recently updated the authentication method for my Go web server from using Bearer tokens to utilizing cookies. During the login process, I now set a cookie for both the token and refresh token like this: a.AuthRepo.StoreInCookie(res.Token, "token&qu ...
I have a file named test.gzip which contains JSON data. {"events": [ {"uuid":"56c1718c-8eb3-11e9-8157-e4b97a2c93d3", "timestamp":"2019-06-14 14:47:31 +0000", "number":732, "user": {"full_name":"0"*1024*1024*1024}}]} The full_name field in the JSON data c ...
Currently, I'm struggling to find a solution in order to properly extract and process the JSON data from . While my code has no issues decoding the JSON data retrieved from , it always returns empty or zero values when directed towards the CoinMarketC ...
I am currently delving into Backend development by constructing a very basic REST API using the gorilla mux library in Go (referring to this tutorial) Here is the code that I have developed so far: package main import ( "encoding/json" "ne ...
Currently I am in the process of adapting a PHP script that is designed to monitor events on a Linux system through supervisor. Forgive me for possibly asking a naive question, but I am struggling to determine what the equivalent of the following code sni ...
Services: - Orders: - ID: $save ID1 SupplierOrderCode: $SupplierOrderCode - ID: $save ID2 SupplierOrderCode: 111111 I am facing a challenge while trying to convert a dynamic YAML string to JSON format. Since the source data ...
In my current project, I am developing the frontend application using NextJS and incorporating next auth for user authentication with email and password login. The backend is implemented in GoLang as a separate code base. When a user logs in, a request is ...
In my code, there's a package called variables which contains an interface Variable, and two structs that implement the methods in the interface - NumericalVariable and TextualVariable. Here is how they are structured... package variables type Variab ...
I am in the process of constructing a body for a POST request relativeurl := "this-is-a-test-url" postBody := fmt.Sprintf("{\"requests\": [{\"httpMethod\": \"GET\",\"rela ...
I have a dictionary data structure containing words and their meanings in the format {{"word name":"word meaning"},{"word name":"word meaning"},...}. I am attempting to convert this into a map of the words, using the interface{} type. However, I am havin ...
One of the key features in my package is the ability for users to define the backend database column name explicitly for their fields, if they choose to do so. Normally, the package uses the field's name as the column name. However, there are cases where ...