Skip to content

Instantly share code, notes, and snippets.

View VictorKabata's full-sized avatar
💻
Knock, knock. Race condition. Who's there?

Victor Kabata VictorKabata

💻
Knock, knock. Race condition. Who's there?
View GitHub Profile
@VictorKabata
VictorKabata / multipart_upload.go
Created June 27, 2020 21:29 — forked from mattetti/multipart_upload.go
Example of doing a multipart upload in Go (golang)
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
//Retrieves movie detail based on id from SQLite. If not available makes a network call to retrieve movie details from API
suspend fun getMovieDetails(movieId: Int): Flow<MovieDetails> {
val movieDetailsCacheResponse:Flow<MovieDetailsEntity>? = appDatabase.movieDetailsDao().getPopularShows(movieId)
return if (movieDetailsCacheResponse != null) {
Timber.e("MovieDetailsDataSource: Fetching movie details from cache")
return movieDetailsCacheResponse.map { it?.toDomain() }
} else {
Timber.e("MovieDetailsDataSource: Fetching movie details from network")
func main() {
fmt.Println("Starting graphql server...")
}
type Note struct {
ID int `json: "id"`
Title string `json: "title"`
Description string `json: "description"`
Created_At string `json: "created_at"`
}
/**Mock database*/
var notes = []Note{
{1, "Title 1", "Description 1", time.Now().UTC().String()},
func main() {
fmt.Println("Starting graphql server...")
noteType := graphql.NewObject(
graphql.ObjectConfig{
Name: "Note",
Description: "User generated note",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.Int,
fields := graphql.Fields{
"notes": &graphql.Field{
Name: "Get all notes",
Type: graphql.NewList(noteType),
Description: "Get list of all notes",
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
return notes, nil
},
},
rootQuery := graphql.ObjectConfig{
Name: "RootQuery",
Fields: fields,
}
schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
schema, err := graphql.NewSchema(schemaConfig)
if err != nil {
log.Fatalf("Failed to create graphql schema: %v", err)
}
handler := handler.New(&handler.Config{
Schema: &schema,
Pretty: true,
GraphiQL: false,
})
http.Handle("/graphql", handler)
log.Fatal(http.ListenAndServe(":8080", nil))