This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package user | |
import ( | |
"database/sql" | |
"errors" | |
"reflect" | |
"testing" | |
) | |
func Test_GetUserProfile(t *testing.T) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getUser(username string) (User, error) { | |
var userObject User | |
// RISK TO SQL INJECTION EXAMPLE | |
// assuming username = string values from client parameter and we have userObject with user type struct | |
query := `SELECT * FROM users WHERE username = ` + username | |
err := db.QueryRow(query).Scan(&userObject) | |
if err != nil { | |
// handle error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"io" | |
"log" | |
"mime/multipart" | |
"net/http" | |
"os" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"encoding/json" | |
"errors" | |
"fmt" | |
"log" | |
"net/http" | |
"time" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"time" | |
"github.com/lib/pq" | |
"github.com/jmoiron/sqlx" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE users ( | |
id SERIAL PRIMARY KEY, | |
name VARCHAR(20) NOT NULL | |
); | |
INSERT INTO users (name) VALUES | |
('jmgzxzatjp'),('rxdqwcmhxv'),('gzusiinshx'),('jhjpjqhsrr'),('vrneswnoxt'),('bpekyumlzv'),('flhuiyxdle'),('wszpqdormm'),('xkrroujuhz'),('yykggdmxqp'),('vzppqdymnr'),('jeumcmyaoq'),('nbzocspmkl'),('alaqeiahku'),('ytkocojmub'),('rsntfgutiu'),('aagqzcdptb'),('wolovipdas'),('kyuweqouzf'),('vopgcakgkv'),('atpqwfbqwr'),('cdnipomsql'),('ahpiotvbdw'),('jqhmmmoxdb'),('yekgeflnmh'),('kywievcxin'),('ugfkrqnwdb'),('jddtwemlkz'),('pdbfxgirya'),('wlaslsmcpx'),('ndyvbcmfkw'),('aozszmnvff'),('hywjpgosgl'),('omctyuatqz'),('oxmhkohqbp'),('rxjtpcmdkk'),('cswsgqwdrr'),('xxkgykmjjl'),('orwqzjccpj'),('uknhoumwuw'),('sloolmdoqx'),('ypqwgehooi'),('utwrhyyzax'),('mievkiforf'),('jyjrxogslq'),('zaduszxmgo'),('bagtbrowuy'),('hgntanbpdh'),('dlcokydxwa'),('opdgcbvwuw'),('jnsffjeyvf'),('johteybbgl'),('keypoduwbk'),('sqpepbkeem'),('cnrvrfunvk'),('rtaibbtkyq'),('fagiwlepof'),('ayoyskiala'),('gumhopjlik'),('xqyxpbrjru'),('dmcaiek |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func processingRequest(ctx context.Context) { | |
span, ctx := apm.StartSpan(ctx, "processingRequest", "custom") | |
defer span.End() | |
doSomething(ctx) | |
// time sleep simulate some processing time | |
time.Sleep(15 * time.Millisecond) | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/json" | |
"log" | |
"net/http" | |
"time" | |
"github.com/gin-gonic/gin" |