go 언어에서 함수 리턴 타입을 적을 때 ()을 사용할 때 튜플을 표현하지 않는다. 그저 묶음 표현일 뿐이다. 


스칼라에 익숙한 개발자라면 놓칠 수 있는 내용인데,.. 사실 go에는 튜플이 없다...



package main

import "fmt"


func main() {

   fmt.Println(add(1,2))

   x, y := add(1,2)

   fmt.Println(x, y)


   fmt.Println(minus(2,1))

}


func add(x int, y int) (int, int) {

  return x + y, x - y

}



func minus(x int, y int) (int) {

  return x - y

}



결과는 다음과 같다. 


3 -1

3 -1

1



함수의 매개변수를 정의할 때 (x int, y int)를 (x, y int)로 바꿔 사용할 수도 있다. 




func add(x, y int) (int, int) {

  return x + y, x - y

}



func minus(x, y int) (int) {

  return x - y

}






함수의 리턴 타입을 정의할 때 변수명을 지정할 수 있다. 함수 내부에서 바인딩되게 하고 리턴할 때 값을 특별히 지정하지 않아도 된다. 


package main
import "fmt"

func main() {
   fmt.Println(split(1))
}

func split(x int) (y, z int) {
  y = x + 2
  z = x + 10
  return
}


결과는 다음과 같다.

3 11


Posted by '김용환'
,


go 언어에는 멀티라인을 제공한다. 


한번에 `(backslash)를 사용할 수 있고 문자열 concatenation을 사용할 수도 있다. 



코드는 다음과 같다. 


  multilineLiteral1 := `aa

  ㅁㅁㅁㅁ

  `


  fmt.Println(multilineLiteral1)



결과는 다음과 같다.


aa

  ㅁㅁㅁㅁ







double quote로도 수행할 수 있다. 



  multilineLiteral2 := "aa  \n" +

  "ㅁㅁㅁ"


  fmt.Println(multilineLiteral2)


결과는 다음과 같다. 


aa

ㅁㅁㅁ




하지만 간단하지만 go에서는 다음 코드를 지원하지 않는다.  자바/스칼라 개발자에게는 의아할 수 있다..



multilineLiteral3 := "s \\n

  aaa"




multilineLiteral4 := "s \\n"

+  "aaa"

'go lang' 카테고리의 다른 글

[golang] go 언어는 not immutable 언어이다. (string 제외)  (0) 2017.08.29
[golang] 함수 리턴 타입에 괄호 사용하는 예제  (0) 2017.08.29
[golang] Go 공부 시작 링크  (0) 2017.08.29
go 1.5 발표  (0) 2015.06.03
godeps 예제  (0) 2015.04.02
Posted by '김용환'
,


go를 공부할 때, 도움되는 싸이트이다.






go 슬라이드 자료 

https://www.slideshare.net/songaal/lets-go-45867246

Let's Go (golang) from Song Sang




go 첫 시작

https://go-tour-kr.appspot.com/#1


이재홍님의 한글 책

http://pyrasis.com/private/2015/06/01/publish-go-for-the-really-impatient-book


예제로 배우는 go

http://golang.site/go/article/1-Go-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-%EC%96%B8%EC%96%B4-%EC%86%8C%EA%B0%9C



go by example

https://gobyexample.com/


디펜던스 관리 - godep

https://github.com/tools/godep


패키지 목록

https://golang.org/pkg/


문서

https://golang.org/doc/

'go lang' 카테고리의 다른 글

[golang] 함수 리턴 타입에 괄호 사용하는 예제  (0) 2017.08.29
[go] 멀티라인 (다중 라인)  (0) 2017.08.29
go 1.5 발표  (0) 2015.06.03
godeps 예제  (0) 2015.04.02
[go lang] command option 받기  (0) 2015.03.28
Posted by '김용환'
,


크롬에서 자동 리프레시가 되게 해주는 gulp livereload를 설치할 수 있다 

ctrl + f 누르지 않고도 데이터가 수정되자마자 사용자가 바로 바뀌어진 문서를 보게 할 수 있다. 





gulp 설치


$ npm install --save-dev gulp gulp-watch gulp-livereload

$ npm link gulp



gulpfile.js 파일


$ vi  gulpfile.js


var gulp = require('gulp');

var pug = require('gulp-pug');

var less = require('gulp-less');

var minifyCSS = require('gulp-csso');


gulp.task('html', function(){

  return gulp.src('client/templates/*.pug')

    .pipe(pug())

    .pipe(gulp.dest('build/html'))

});


gulp.task('css', function(){

  return gulp.src('client/templates/*.less')

    .pipe(less())

    .pipe(minifyCSS())

    .pipe(gulp.dest('build/css'))

});


gulp.task('default', [ 'html', 'css' ]);



gulp를 실행한다. 


$ gulp watch


[20:15:03] Using gulpfile ... gulpfile.js

[20:15:03] Starting 'watch'...



크롬에서는 livereload 플러그인을 실행한다. 



완료!




참고 : http://hochulshin.com/gulp-livereload-sample/

'etc tools' 카테고리의 다른 글

[git] 여러 commit을 하나로 병합하기  (0) 2017.10.24
[git] git reset hard  (0) 2017.09.01
[github] PR(pull request) 하기  (0) 2017.08.17
github page 웹으로 생성하기  (0) 2017.08.17
[influxdb] influxdb clustering은 무료 버전?  (0) 2017.03.23
Posted by '김용환'
,


cql에서 필드마다의 저장 시간을 확인하고 싶다면 WRITETIME을 사용한다.



SELECT "email", WRITETIME("email"), "location", WRITETIME("location")

FROM "member"

WHERE "username" = 'samuel.kim';



 email               | writetime(email) | location | writetime(location)

---------------------+------------------+----------+---------------------

samuel.kim@google.com | 1501879907661000 |      seoul |    1502024896943000



참고

http://docs.datastax.com/en/cql/3.1/cql/cql_using/use_writetime.html

Posted by '김용환'
,




maven에서 매개변수를 전달하는 방법은 exec.args를 사용한다.


특별히 스페이스가 포함된 문자열을 하나의 토큰으로 전달하려면 sing quote를 사용한다. 



예제


$ maven exec:java -Dexec.mainClass=com.google.photo.Main  -Dexec.args="local 'a   a' "




만약 classpath나 jvm 옵션을 추가하고 싶다면 아래와 같이 사용한다.



예제



$ mvn exec:exec -Dmaven.run.skip=true -Dexec.executable="java"  -Dexec.args="-classpath /usr/local/apache-storm-1.0.1/lib/*:/home/google/lib/photo.jar com.google.photo.Main local"



Posted by '김용환'
,


트레이싱 API





https://eng.uber.com/distributed-tracing/


https://research.google.com/pubs/pub36356.html



uber가 영향받은 구글의 dapper 논문


https://static.googleusercontent.com/media/research.google.com/ko//pubs/archive/36356.pdf

Posted by '김용환'
,



https://github.com/coreos/etcd/releases/ 을 접근하니 3.2.6이 최신이다. 

os 버전별로 바이너리를 다운받고 압축을 푼 디렉토리 밑에 실행하면 된다.



ETCDCTL_API의 값이 설정되야 잘 돌아간다. 

$ ETCDCTL_API=3


또는 .bash_xx에 추가한다. 

EXPORT ETCDCTL_API=3 




version을 확인한다. 


$ ./etcdctl version

etcdctl version: 3.2.6

API version: 3.2




2.x에서 사용되던 ls는 안먹힌다.. 조금씩 바꾼 형태이다. 

$ ./etcdctl ls /

Error: unknown command "ls" for "etcdctl"

Run 'etcdctl --help' for usage.

Error:  unknown command "ls" for "etcdctl"



put, get 예제


$ /etcdctl put foo bar

OK


$ ./etcdctl get foo

foo

bar



from-key 예제



$ ./etcdctl put foo bar

OK


$ ./etcdctl put foo bar

OK


$ ./etcdctl put foo1 bar1

OK


$ ./etcdctl put foo2 bar2

OK


$ ./etcdctl put foo3 bar3

OK


$ ./etcdctl get foo

foo

bar

$ ./etcdctl get --from-key foo1

foo1

bar1

foo2

bar2

foo3

bar3

$ ./etcdctl get foo1 foo3

foo1

bar1

foo2

bar2







etcd 2.x의 ls 와 비슷한 커맨드 from-key


$ ./etcdctl put x y

OK

$ ./etcdctl put y 1

OK

$ ./etcdctl get --from-key ''

x

y

y

1






delete 예제



$ ./etcdctl del foo

1

$ ./etcdctl get foo




$ ./etcdctl put key val

OK

$ ./etcdctl del --prev-kv key

1

key

val

$ ./etcdctl get key




$ ./etcdctl put a 123

OK

$ ./etcdctl put b 456

OK

$ ./etcdctl put z 789

OK

$ ./etcdctl del --from-key a

6

$ ./etcdctl get --from-key a




 ./etcdctl put zoo val

OK

$ ./etcdctl put zoo1 val1

OK

$ ./etcdctl put zoo2 val2

OK

$ ./etcdctl del --prefix zoo

3

$ ./etcdctl get zoo2





원자잭 트랙잭션 txn 예제



$ ./etcdctl txn -i

compares:

mod("key1") > "0"


success requests (get, put, delete):

put key1 "111"

put key2 "222"


failure requests (get, put, delete):


SUCCESS


OK


OK

$ ./etcdctl get key1

key1

111

$ ./etcdctl get key2

key2

222




클러스터 모드롤 실행할 때는 로컬이 아닌 3대의 장비에서 실행시키는 것이 좋다..




Posted by '김용환'
,


fluentd에서 http query의 모든 매개변수 값을 key,value로 포함시키려면 


fluent-plugin-extract_query_params를 설치하고 @type extract_query_params를 활용한다. 




참고 

https://github.com/kentaro/fluent-plugin-extract_query_params


Imagin you have a config as below:

<filter test.**>
  @type extract_query_params

  key            url
  only           foo, baz
</match>

And you feed such a value into fluentd:

"test" => {
  "url" => "http://example.com/?foo=bar&baz=qux&hoge=fuga"
}

Then you'll get re-emmited tag/record-s below:

"extracted.test" => {
  "url" => "http://example.com/?foo=bar&baz=qux&hoge=fuga"
  "foo" => "bar",
  "baz" => "qux"
}


'Cloud' 카테고리의 다른 글

[openstack] Rally + Tempest  (0) 2017.09.02
[etcd] etcd 설치와 간단 예제  (0) 2017.08.23
[펌] fluentd 성능  (0) 2017.08.21
[td-agent] td-agent 설치 및 테스트  (0) 2017.08.18
fluentd 공부  (0) 2017.08.16
Posted by '김용환'
,




일래스틱서치는 인덱스의 필드 데이터의 데이터 타입을 지정하지 않으면 자동으로 데이터 타입 매핑을 한다. 그러나 데이터 오류 또는 일래스틱서치 내부 동작에 의해 좀더 큰(broader) 타입으로 자동 매핑을 하지 않도록 동적으로 일래스틱서치의 필드에 타입을 지정하는 기능이다. 



예를 들어, integer 값 필드를 일래스틱서치 내부적으로 integer 타입로 받아들이다가 데이터 일부가 오류가 생겨서 1.1이 오면 모두 double로 변경될 수 있다. 자동 타입 변경이 되지 않도록 설정할 수 있는 기능이라 할 수 있다. 



https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html#dynamic-templates


 "dynamic_templates": [
    {
      "my_template_name": { 
        ...  match conditions ... 
        "mapping": { ... } 


Posted by '김용환'
,