- golang option pattern - option struct ``` type option struct { Name string Age int } ``` - option func type ``` type Option func(*options) func F1(name string) Option{ return fun(op *option){ op.Name = name } } } func F2(age int) Option{ return func(op *option) { op.Age= age } } ``` - usage ``` func NewOption(setters ...Option){ op := &option{} for s:=range setters{ s(op) } return...
2022/12/15
2022/12/14
what is good bulk insert
To get optimal write throughput for bulk loads, partition your data by primary key with this pattern: Each partition contains a range of consecutive rows. Each commit contains data for only a single partition. A good rule of thumb for your number of partitions is 10 times the number of nodes in your Cloud Spanner instance. So if you have N nodes, with a total of 10*N partitions, you can assign rows to partitions by: Sorting your data by primary key. Dividing it into 10*N separate sections. Creating a set of worker tasks that upload...
golang chunk
- chunk ``` func Chunk[T any](items []T, chunkSize int) [][]T { var chunks = make([][]T, 0, (len(items)/chunkSize)+1) for chunkSize < len(items) { items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize]) } return append(chunks, items) } //Arrayをスライシングすると、リターンされたSliceのcapはstartIndexからArrayの最期までのサイズです。 //しかし、次のようにスライシングする時、maxIndexを追加してcapのサイズを調整することが出来ます。 //slice[startIndex:endIndex:maxIndex] ...
big array goroutine
- https://qiita.com/tutuz/items/057452fbbe9a5ae26d37 - multi goroutine to loop array ``` slice := []string{"a", "b", "c", "d", "e"} sliceLength := len(slice) var wg sync.WaitGroup wg.Add(sliceLength) fmt.Println("Running for loop…") for i := 0; i < sliceLength; i++ { go func(i int) { defer wg.Done() val := slice[i] fmt.Printf("i: %v, val: %v\n", i, val) }(i) } wg.Wait() fmt.Println("Finished for loop") ``` - 課題はエラー検知とgoroutineの数の制御、errgroupの登場...
2022/12/08
golang fmt %q
文字列を””で囲んで出力する。これで実際の を””に表現して、わかりやすい spannerのgolang clientで%qを使っているIt's just quite a strange decision made by Google here, to assume that the String() function is only used for logging and it's ok to add quotes...package mainimport ( "fmt")func main() { str := "Gopherくん" slice := []string{"g", "o", "h", "e", "r"} integer := 12450 fmt.Printf("1:出力は %q となります。\n", str) fmt.Printf("2:出力は %s となります。\n", str) fmt.Printf("3:出力は %q となります。\n", slice) fmt.Printf("4:出力は %s となります。\n", slice) fmt.Printf("5:出力は %d となります。\n", integer) fmt.Printf("6:出力は %q となります。\n",...
2022/12/07
spanner nullable data type golang
spanner nullable data type```// NullableValue is the interface implemented by all null value wrapper types.type NullableValue interface { // IsNull returns true if the underlying database value is null. IsNull() bool}```- how to use - difference between null,"","someValue" - null - spanner.NullString(valid=false) - "" - spanner.NullString(valid=true,value="") - update(value[*NullableValue]->model[NullableValue]) - update target items - value is not nil - not update target items - value is nil -...
go instal where ?
go install xxx..xxx==>the location is ~/go/binso ,set the ~/go/bin to .bash_profiles 's PATHgo versiongo help environment``` GOBIN The directory where 'go install' will install a command. GOPATH For more details see: 'go help gopath'. GOROOT The root of the go tree.```go help gopath```If the environment variable is unset, GOPATH defaultsto a subdirectory named "go" in the user's home directory($HOME/go on Unix, %USERPROFILE%\go on Windows),unless that directory holds a Go distribution.Run "go env GOPATH" to see the current GOPATH.```go env GOPATH==>~/gogo...
golang model
https://go.dev/play/p/B7ErJjt8JqU modelの役割ですが、① entity,usecase,repo,querierなど繋ぐ② validationなどの業務ロジックの担保②の配慮でmodelのfiledは非公開で、Setter都度Validationする、常に完璧な状態を求めて、trade-offで使いにくく、①の役割を損する。なので、①の役割をPrimativeなstruct(一旦voと呼ぶ)に分担する方いいかなと思う。vo<=>modelの変換は手間ですが、複雑ではないので、ある程度自動作成できる。
-- go.mod --module samplego 1.19-- model/name.go --package modelimport "errors"type Name struct { string}func NewName(v string) (Name, error) { n := Name{v} if err := n.validate(); err != nil { return Name{}, err } return n, nil}func (n Name) validate()...
2022/12/02
2022/12/02
mock static java method in kotlin use mockk
beforeEach: mockkStatic(LocalDateTime::class)test :coEvery { LocalDateTime.now() } returns ...
2022/11/25
mockk kotlin no return value
val mockedFile = mockk<File>()
every { mockedFile.write(any()) } returns U...
Kotlin mocking a var with get/set using Mockk
coEvery { someClass getProperty "now"} returns ...
2022/11/22
select force index,use index,ignore index
select * from table use index(index1,index2)select * from table ignore index(index1)select * from table force index(inde...
sql join on using
select * from join1 inner join join2 on join1.join1_id = join2.join1_id;select * from join1 inner join join2 using(join1_id);usingで同じ名の列は一つになり、列減少する基本、usingの方が便利と...
big query 配列 uunest
キー以外の内容はkey-valueの配列かなRDBと違う配列の中身を取るに UNNEST関数を使うNESTは階層で、UNNESTは階層をなくす、平準化にする例えば。epは配列でselect 他のカラム、ep.key, ep.value.string_valuefrom xxxx, UNNEST(配列のカラム) ep以上は検索できるが、問題は、配列中の値の複数を条件として検索できないep.a=a AND ep.b=b で取れないで、それで別々に検索して、JIONなどのSQL技で解決。複雑なSQLになる。SELECT GENERATE_ARRAU(11,33,2) AS somestart,end,step(default 1)+--------------------------------------------------+| some |+--------------------------------------------------+|...
cloud spanners shard
- record->split->node - どこに保存されるはprimary keyで決める- autoIncrementの仕組みがない、順番に保存するのは特定のnodeに集中するので、望ましくない(hotspot発生)- autoIncrement以外のIDの生成方法uuid 1~uuid4 - uuid1はtimestampペース、mac addressを使う連番になる可能性- uuid4はランダムの乱数で、分散性が高い、衝突になる可能性が0ではないsnowflakeULIDtimestampを使ってIDを生成する場合、どうしても分散率が低い。なので、shardId=hash(key)%NPRIMARY KEY(shardId,分散率低い値のcolumn)の複合キーで対応する内部のHash関数を使う。 - farm_fingerprint -...
2022/07/04
@MockkBean SpykBean
@MockkBeanではevery文で定義しなかった関数は何も返さない関数に置き換わりますが、@SpykBeanではevery文で定義しなかった関数はそのままオリジナルの関数の定義を引き継ぎ...
2022/07/03
When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead
Use config.setAllowedOriginPatterns("*") instead of config.setAllowedOrigins(Collections.singletonList("*"...
2022/06/29
CONDITIONS EVALUATION REPORT
logging.level.org.springframework.boot.autoconfigure=ER...
What is username and password when starting Spring Boot with Tomcat?
user name: userpassword: 2022-06-29 17:17:09.586 WARN 1242 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :Using generated security password: 7b324ed9-1181-461e-bd5e-0a26ebdd3013This generated password is for development use only. Your security configuration must be updated before running your application in producti...
curl post json file
curl -X POST -H 'Content-type:application/json' \ --data-binary @some.json some_...
2022/02/28
launch is only available since Kotlin 1.3 and cannot be used in Kotlin 1.2
kotlin compile style&nb...
2022/02/20
mac java version
久しぶりにJavaを触った。many many jdks ...so how to mange so many jdksshow jdks version on your mac pc/usr/libexec/java_home -Venv is a good idea. python->pyenvnode->nodenvruby->rbenvgolang->gvmjava->jenvinstall jenv brew install jenv export JENV_ROOT="$HOME/.jenv"echo 'eval "$(jenv init -)"' >> ~/.bash_profilesource ~/.bash_profilejenv doctoradd jdk path to jenvjenv add /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Homeuse some versionjenv local 11 &nb...
2022/02/16
Gradle The JavaExec.main property has been deprecated
deprecated gradle features were used in this build, making it incompatible with gradle 8.0. => add ↓ to gradle.propertiesorg.gradle.warning.mode=allthen he JavaExec.main property has been deprecatedchange build.gradleplugins { id "application"}apply plugin : "java"application { mainClass = 'xxx.xxx'}then gradle ...
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
slf4j has more implements. but you have none in you class path, that is the reason.add it gradle examplebuild.gradle```dependencies {
implementation 'org.slf4j:slf4j-log4j12:1.7.36'
}...
intelliJ gradle version
use gradle from : can select some gradle&nb...