2018/10/25

gvm GoのVersion管理を楽に

GoのVersion管理を楽に
<(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
source /Users/xxx/.gvm/scripts/gvm
gvm version
gvn listall
//-B binary only,no source file
gvm install go1.9.5 -B
gvm install go1.11.1 -B
gvm use go1.11.1 --default

go version

///Users/kouha.shu/.gvm/gos/go1.11.1
echo $GOROOT

///Users/xxx/.gvm/pkgsets/go1.11.1/global
echo $GOPATH

2018/10/19

gorm transaction

TransactionsTo perform a set of operations within a transaction, the general flow is as below.
// begin a transaction
tx := db.Begin()

// do some database operations in the transaction (use 'tx' from this point, not 'db')
tx.Create(...)

// ...

// rollback the transaction in case of error
tx.Rollback()

// Or commit the transaction
tx.Commit()

2018/10/16

Graphql


more easier than RESTAPIClient側のRequestを柔軟に対応できる感じで
 QueryLanguage!条件は自分で指定し、結果を返す
 QueryLanguageをサポートするServicesTypeFieldFunctions

What kinds of objects might they return? What fields are available on those sub-objects? That's where the schema comes in.

A GraphQL service is created by defining types and fields on those types,then providing functions for each field on each type.

Once a GraphQL service is running (typically at a URL on a web service), 
 it can be sent GraphQL queries to validate and execute. 
 A received query is first checked to ensure it only refers to the types and fields defined, then runs the provided functions to produce a result.

Learn more about GraphQL—the query language, type system, how the GraphQL service works, 

Like many type systems, GraphQL supports interfaces

the query has exactly the same shape as the result. This is essential to GraphQL, because you always get back what you expect, and the server knows exactly what fields the client is asking for.==>後で統計、分析できるね!

GraphQL queries can traverse related objects and their fields, 
 letting clients fetch lots of related data in one request, 
 instead of making several roundtrips as one would need in a classic REST architecture.

GraphQL, every field and nested object can get its own set of arguments, making GraphQL a complete replacement for making multiple API fetches. 
↓↓heightFOOT単位で返す
{
  human(id: "1000") {
    name
    height(unit: FOOT)
  }
}

have reusable units called fragments. Fragments let you construct sets of fields, and then include them in queries where you need to.
=>重複する部分をFragmentとして定義し、使うところでIncludeする感じ
    …some Fragement


・「query HeroNameAndFriends
  query->operation type
      HeroNameAndFriends—>operation name


 GraphQL has a first-class way to factor dynamic values out of the query, and pass them as a separate dictionary. These values are called variables.
    can have default value
    @include—>directive 
     @skip(if: Boolean)—>directive 
 query HeroNameAndFriends($episode: Episode = XXX,$withFriends) {
    hero(episode: $episode) {
            name
            friend @include(if: $withFriends)
   }
    }


mutationー>POST it (更新) then  GET 更新結果
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
  createReview(episode: $ep, review: $review) {
    stars
    commentary
  }
}

While query fields are executed in parallel, mutation fields run in series, one after the other.


inline Fragment
query HeroForEpisode($ep: Episode!) {
  hero(episode: $ep) {
    name
#__typename, a meta field, when you dont know the type, you can use it 
# when ep is Droid
    ... on Droid {
      primaryFunction
    }
# when ep is Human
    ... on Human {
      height
    }
  }
}


query HeroNameAndFriends {
  hero {
    name
    friends {
      name
    }
  }
}

query(request) Sample

{
  human(id: "1000") {
    name
    height
  }
   # Queries can have comments!
    friends {
      name
    }
}

DataResponse
{
  "data": {
    "hero": {
      "name": "R2-D2",
     height: 170.2
      "friends": [
        {
          "name": "Luke Skywalker"
        },
        {
          "name": "Han Solo"
        },
        {
          "name": "Leia Organa"
        }
      ]
    }
  }
}


docker gae EMPTRY_RESPONSE


docker+gaeの構成で、Admin Consoleを見たいが、EMPTRY_RESPONSEで見えない。。

EMPTRY_RESPONSE means that the TCP connection into the docker container seemed to be sucessful, 
however the server side closed the connection without sending anything back. 

curl -v http://localhost:8000 


Your issue is that you are binding to the 127.0.0.1:8025 inside your code. This makes the code work from inside the container but not outside.
You need to bind to 0.0.0.0:8025 to bind to all interfaces inside the container. So traffic coming from outside of the container is also accepted by your Go app

When you get this error it means youve exposed the right port in your Dockerfile, 
but you have to make sure the app within your container is binding to 0.0.0.0 instead of localhost or 127.0.0.1.
I got this error using Angular CLIng serve within a container. 
I had to add –host=0.0.0.0 to the ENTRYPOINT arguments. 
If youre using a different framework check for a similar command-line argument, configuration parameter or setting.

・解決!—port 8080 --admin_port 8000 --skip_sdk_update_check yes --host 0.0.0.0
--admin_hostデフォルトはlocalhost—admin_host 0.0.0.0 を追加して見える
--admin_host=ADMIN_HOST
ローカル開発用サーバーの管理コンソールがバインドするホスト名(デフォルト: localhost)。
--admin_port=ADMIN_PORT

2018/10/11

window7 テザリング 制限付き接続

家のAU光が接続障害になり、
携帯でテザリングし、Macはすぐ上手く行くが、
window7 テザリング 制限付き接続になり、ネットアクセスできない。。一瞬できたこともあり、

電源プランを高パフォーマンスにし、上手くできた。。。意味が何となくわからない。。