How to add a string to an URL in golang? - rest

I am new to golang and trying this for the first time. I have to call yahoo finance api(YQL) to get the stock price of the symbol in json format.
Here is the api:
http://query.yahooapis.com/v1/public/yql?q=select%20LastTradePriceOnly%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22AAPL%22,%22FB%22,%22GOOG%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
For now i have hard coded the symbol(AAPL,FB, GOOG) in the above select query but these symbols will be coming from the user, it should be dynamic. How should i add the input(symbol) to the above query in golang?
Thanks for the help in advance.

If you have the symbols (provided by the users) as a string array parameter (like: "symbols", being string["\"AAPL\"", "\"FB\"", "\"GOOG\""]), you can use strings/#Join to produce the right string:
s := strings.Joins(symbols, ",")
Then (as detailed in "Encode / decode URLs"), use net/url/#QueryEscape to get the final url string for symbols:
url := "http://query.yahooapis.com/v1/public/yql?q=select%20LastTradePriceOnly%20from%20yahoo.finance.quote%20where%20symbol%20in%20(" +
url.QueryEscape(s) +
")&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"

Related

Restrict Countries and Cites in Flutter using session token

the following string of url correctly gives me locations within my country:
String autocompleteURL="https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$placeName&key=$mapKey&sessiontoken=1234567890&components=country:my";` //no Error
'my' gives all cities in Malaysia.
However, I want to restrict it to malacca within malaysia.I don't know how to use components for a particular city using session token.I searched the autocomplete documentation from google developers website.
After that, I changed the above code into:
String autocompleteURL= "https://maps.googleapis.com/maps/api/place/autocomplete/xml?input=$placeName&types=establishment&location=2.25386,-102.27273&radius=500&key=$mapKey"; //error after change.
However, only this line gives me error after change.
Here, long and latitude values are the values for Malacca.
I am using my program in flutter.
change your output type from xml to json :
String autocompleteURL= "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=$placeName&types=establishment&location=2.25386,-102.27273&radius=500&key=$mapKey"; //error after change.

Swift string with key-value, is this format standard ? How can I get it as a dictionary?

I work with an array of string, each string var is a coded object.
I want to decode the object, when I print a string var I get something structured like that :
"firstName=\"Elliot\" lastName=\"Alderson\" gender=\"male\" age=\"33\",some description I also need to get"
Is that a standard format to store key value properties ? I can't find anything on internet. The keys are always the same so that's not a big deal to get theses values as a dictionary but I would like to know if there is like a best practice method to get theses data instead of just searching for each key and then reach value from the first quote to the second one (for each value)
Because my file is 30000 lines so I better choose the more optimized way.
Thanks !

How to find a sub-string of a text in Tableau based on a separator character

I have a list of URL's in my data. This URL information also include the URL parameters. I want to find out a list of unique url's. I mean
https://root/member_portal/javax.faces.resource/beanvalidation.js.xhtml?ln=js
https://root/member_portal/javax.faces.resource/beanvalidation.js.xhtml?ln=js&v=6.0.0 should be the same.
Is there a text operation to create a calculated field which will find the substring before the "?" sign in the URL?
Assuming that your parameterised URL data is kept in [URL] field; you may use below formula to strip the main URL part:
LEFT([URL],FIND([URL], "?")-1)
FIND returns the position of "?" character in our URL field data. And LEFT returns everything before that index - 1.

Insert field name with dot in mongo document

A Meteor server code tries to insert an object into a Mongo collection. The value of one of the property is a string which contains a dot i.e. ".".
Meteor terminal is complaining :-
Error: key Food 1.1 and drinks must not contain '.'
What does this mean and how to fix it?
let obj = {
food: group,
rest: rule,
item: item[0],
key: i
};
FoodCol.insert(obj);
edit
The suggested answer by Kishor for replacing the "." with "\uff0E" will produce a space after the dot which is not what a user expects.
From this link, How to use dot in field name?
You can replace dot symbols of your field name to Unicode equivalent
"\uff0E":
Update: As Fred suggested, please use "\u002E" for "."
We solved this issue by encoding (Base64) the key before insertion and decode after taking out from the db. Since we consume the document as it is and query fields are different and their keys are not encoded.
But if u want to make query using this key or the key should be readable to the user, this solution will be not be suitable.

Query string parsing as number when it should be a string

I am trying to send a search input to a REST service. In some cases the form input is a long string of numbers (example: 1234567890000000000123456789). I am getting 500 error, and it looks like something is trying the convert the string to a number. The data type for the source database is a string.
Is there something that can be done in building the query string that will force the input to be interpreted as a string?
The service is an implementation of ArcGIS server.
More information on this issue per request.
To test, I have been using a client form provided with the service installation (see illustration below).
I have attempted to add single and double quotes, plus wildcard characters in the form entry. The form submission does not error, but no results are found. If I shorten the number("1234"), or add some alpha numeric characters ("1234A"), the form submission does not error.
The problem surfaced after a recent upgrade to 10.1. I have looked for information that would tie this to a known problem, but not found anything yet.
In terms of forcing the input to be interpreted as a string, you enclose the input in single quotes (e.g., '1234567890000000000123456789'). Though if you are querying a field of type string then you need to enclose all search strings in single quotes, and in that case none of your queries should be working. So it's a little hard to tell from the information you've provided what exactly you are doing and what might be going wrong. Can you provide more detail and/or code? Are you formatting a where clause that you are using in a Query object via one of Esri's client side API's (such as the JavaScript API)? In that case, for fields of data type string you definitely need to enclose the search text in single quotes. For example if the field you are querying were called 'FIELD', this is how you'd format the where clause:
FIELD = '1234'
or
FIELD Like '1234%'
for a wildcard search. If you are trying to enter query criteria directly into the Query form of a published ArcGIS Server service/layer, then there too you need to enclose the search in single quotes, as in the above examples.
According to an Esri help technician, this is known bug.