<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by A.Kadir Mutlu on Medium]]></title>
        <description><![CDATA[Stories by A.Kadir Mutlu on Medium]]></description>
        <link>https://medium.com/@s4l1h?source=rss-43261ee2c8e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*4G8Rl3DmH30tHPu-.jpg</url>
            <title>Stories by A.Kadir Mutlu on Medium</title>
            <link>https://medium.com/@s4l1h?source=rss-43261ee2c8e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 13:17:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@s4l1h/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to install Kind and Istio ingress controller]]></title>
            <link>https://medium.com/@s4l1h/how-to-install-kind-and-istio-ingress-controller-3b510834c762?source=rss-43261ee2c8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b510834c762</guid>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[kind]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[A.Kadir Mutlu]]></dc:creator>
            <pubDate>Sat, 01 Apr 2023 05:33:37 GMT</pubDate>
            <atom:updated>2023-04-01T05:33:37.217Z</atom:updated>
            <content:encoded><![CDATA[<p>We are currently working on a project that involves Istio and the Kubernetes controller. In order to make the development process easier, I decided to use Kind to install Istio. Kind allows for easy creation of Kubernetes clusters on your computer. You can find more details about Kind and its installation process at this link: <a href="https://kind.sigs.k8s.io/docs/user/quick-start#installation">https://kind.sigs.k8s.io/docs/user/quick-start#installation</a>.</p><p>When you install Istio to a Kind cluster, you need to do port forwarding to ensure that Istio works properly. Therefore, we will be exposing ports 80 and 443 on the Kind cluster and forwarding them to Istio.<br><strong>It’s important</strong> to note that if you have <strong>already installed the Kind cluster</strong>, you cannot expose additional ports, and you need to do it when you create the cluster (I couldn’t find this information in the documentation).</p><p>Let’s create a Kind configuration file and use it to create the cluster. As you can see in the configuration file, there are <strong>extraPortMappings</strong> that we will be using.</p><pre>kind: Cluster<br>apiVersion: kind.x-k8s.io/v1alpha4<br>nodes:<br>  - role: control-plane<br>    kubeadmConfigPatches:<br>      - |<br>        kind: InitConfiguration<br>        nodeRegistration:<br>          kubeletExtraArgs:<br>            node-labels: &quot;ingress-ready=true&quot;<br>    extraPortMappings:<br>      - containerPort: 80<br>        hostPort: 80<br>        protocol: TCP<br>      - containerPort: 443<br>        hostPort: 443<br>        protocol: TCP</pre><pre>kind create cluster --config=./kind.yaml</pre><p>I assume that you already have Istioctl installed on your computer. If you don’t have it, you can check out the following link for instructions on how to install it: <a href="https://istio.io/latest/docs/setup/install/istioctl/">https://istio.io/latest/docs/setup/install/istioctl/</a>.</p><pre>istioctl install</pre><p>This command will install Istio in your cluster. After that, we need to patch the Istio ingress. If you didn’t customize the deployment, the name of the Istio ingress controller is <strong>istio-ingressgateway</strong>, and it is located in the <strong>istio-system</strong> namespace. Before running the command, it’s recommended that you perform a dry run first to ensure that you are satisfied with the result.</p><pre>kubectl patch deployments.apps --dry-run=client -o yaml -n istio-system istio-ingressgateway -p &#39;{&quot;spec&quot;:{&quot;template&quot;:{&quot;spec&quot;:{&quot;containers&quot;:[{&quot;name&quot;:&quot;istio-proxy&quot;,&quot;ports&quot;:[{&quot;containerPort&quot;:8080,&quot;hostPort&quot;:80},{&quot;containerPort&quot;:8443,&quot;hostPort&quot;:443}]}]}}}}&#39;</pre><p>After you have reviewed the dry run and are satisfied with the changes, you can apply the patch to the Istio ingress controller.</p><pre>kubectl patch deployments.apps -n istio-system istio-ingressgateway -p &#39;{&quot;spec&quot;:{&quot;template&quot;:{&quot;spec&quot;:{&quot;containers&quot;:[{&quot;name&quot;:&quot;istio-proxy&quot;,&quot;ports&quot;:[{&quot;containerPort&quot;:8080,&quot;hostPort&quot;:80},{&quot;containerPort&quot;:8443,&quot;hostPort&quot;:443}]}]}}}}&#39;</pre><p>In essence, what we are doing is adding a <strong>hostPort</strong> to the Istio ingress gateway pod, which exposes the Istio ingress gateway pod port to the host, allowing it to listen on the specified host port. for more details google it “kubernetes hostPort”</p><p>You can find all of the commands here: <a href="https://gist.github.com/s4l1h/83145e1e8ba9445809fc96effda91c21">https://gist.github.com/s4l1h/83145e1e8ba9445809fc96effda91c21</a></p><p><strong>Note</strong>: Another way to achieve this is by connecting to the Kind cluster via the docker exec command and using the <a href="https://linux.die.net/man/1/socat">socat</a> command.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b510834c762" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building and Publishing A Container Image with Gitlab CI and Kaniko]]></title>
            <link>https://medium.com/@s4l1h/building-and-publishing-a-container-image-with-gitlab-ci-and-kaniko-889e854fb7f1?source=rss-43261ee2c8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/889e854fb7f1</guid>
            <category><![CDATA[kaniko]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[gitlab-ci]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[A.Kadir Mutlu]]></dc:creator>
            <pubDate>Sat, 07 Sep 2019 23:02:58 GMT</pubDate>
            <atom:updated>2019-09-17T21:11:56.275Z</atom:updated>
            <content:encoded><![CDATA[<p>Gitlab CI/CD, Kaniko, Amazon Elastic Container Registry, Google Cloud Registry</p><p>In this article, I would like to explain how to build a container image on Gitlab CI and publish to the <strong>Amazon Container Registry</strong>, <strong>Google Cloud Registry</strong> and<strong> Gitlab Registry.</strong></p><p>The project will be a simple hello world <strong>Go</strong> project.</p><p>Our <strong>Dockerfile</strong> is looking like this.</p><pre>#Build to Project<br>FROM golang:latest AS build-source<br>WORKDIR /app<br>COPY ./app /app<br>ENV CGO_ENABLED=0<br>RUN go build -o main .<br><br># Compress to binary file<br>FROM alpine:latest AS compressor<br>RUN apk add upx<br>WORKDIR /app<br>COPY --from=build-source /app/main /app/main<br>RUN upx --overlay=strip --best /app/main<br><br># final stage<br>FROM alpine:latest<br>WORKDIR /app<br>COPY --from=compressor /app/main /app/main<br># Add Tini<br>RUN apk add --no-cache tini<br>ENTRYPOINT [&quot;/sbin/tini&quot;, &quot;--&quot;]<br><br># expose port<br>EXPOSE 8080<br># app<br>CMD [&quot;/app/main&quot;]</pre><p>Our <strong>Go</strong> project <strong>main.go </strong>file. Just simple hello world.</p><pre>package main<br><br>import (<br>	&quot;fmt&quot;<br>	&quot;net/http&quot;<br>)<br><br>func main() {<br>	http.HandleFunc(&quot;/&quot;, func(w http.ResponseWriter, r *http.Request) {<br>		fmt.Fprintf(w, &quot;Hello from Amed!&quot;)<br>	})<br>	http.ListenAndServe(&quot;:8080&quot;, nil)<br>}</pre><p>Gitlab CI is a very powerful CI tool that comes built-in with Gitlab.</p><p>When you want to create a container image by using Gitlab CI. The problem occurs in this section because Gitlab CI runs a container for this job. docker in docker (<strong>dind</strong>) needs some special permissions for achieving that.<br>Why you shouldn’t use docker in docker? <strong>jpetazzo</strong> explains that in <a href="https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/">this article</a>.</p><p>If you are using the Gitlab free version you should install your runner and you will overcome to <strong>dind</strong> and docker privileged mode.</p><p>We are going to use <a href="https://github.com/GoogleContainerTools/kaniko">Kanico</a> to handle the problem.</p><p>Kanico comes built-in support for <strong>Amazon ECR</strong> and <strong>Google Cloud Registry </strong>for more details please check out Kaniko Documentation (You can use on Kubernetes as well.)</p><h3>Gitlab Container Registry.</h3><p>It’s very easy to build and push a container image to Gitlab Container Registry. In the official documentation of Gitlab, you can find information about Kaniko.<br><a href="https://docs.gitlab.com/ee/ci/docker/using_kaniko.html"><strong><em>Building images with Kaniko and GitLab CI/CD</em></strong></a></p><h3>Amazon Elastic Container Registry</h3><p><strong>Step 1</strong>) We will create a repository from <a href="https://console.aws.amazon.com/ecr/repositories"><strong>here</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-x61NRrSuG8wh_W5SKea7w.jpeg" /></figure><p><strong>Step2) </strong>We are going to create an IAM user and give permission from <a href="https://console.aws.amazon.com/iam/home?region=us-east-1#/users$new?step=details"><strong>here</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*isru1pUWzLHK66OGsQVS_A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UkIUh1hbbCZB3hVdG_VwNg.jpeg" /></figure><p><strong>Step3</strong>) Save your user credential details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYGxbPFYHaf8gNwgFrRoig.jpeg" /></figure><p><strong>Step 4</strong>) We are going to save these credentials and repository details under <br><strong>Gitlab -&gt; Settings -&gt; CI / CD -&gt; Variables</strong>.</p><blockquote>AWS_ACCOUNT_ID, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY , AWS_REPOSİTORY</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ybmooVQmRiSio-Wh1SOZZQ.jpeg" /></figure><p><strong>Step 5</strong>) We are going to create the <a href="https://gitlab.com/s4l1h/kaniko-amazon-elastic-container-registry/blob/master/.gitlab-ci.yml"><strong>.gitlab-ci.yml file</strong></a> in the project root.</p><pre>build:<br>  stage: build<br>  image:<br>    name: gcr.io/kaniko-project/executor:debug<br>    entrypoint: [&quot;&quot;]<br>  script:<br>    - echo &quot;{\&quot;credsStore\&quot;:\&quot;ecr-login\&quot;,\&quot;credHelpers\&quot;:{\&quot;$AWS_ACCOUNT_ID.dkr.ecr.region.amazonaws.com\&quot;:\&quot;ecr-login\&quot;}}&quot; &gt; /kaniko/.docker/config.json<br>    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $AWS_REPOSITORY:$CI_COMMIT_TAG<br>  only:<br>    - tags</pre><p>In this CI configuration when we push any tag to repository Gitlab CI will trigger to a job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2Hl6QaTra7qrCbd-KFwaw.jpeg" /></figure><p>When the job finished. You will be able to see your container image in the <strong>Amazon Elastic Container Registry.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlZgZT9hJnssQac7H9yRnA.jpeg" /></figure><h3>Google Container Registry</h3><p>We need to create a service account for Gitlab can push image to Google Container Registry.</p><p><strong>Step1</strong>) Go to<strong> IAM &amp; admin -&gt; service accounts </strong>and create an account and give storage admin permission. Like they <a href="https://cloud.google.com/container-registry/docs/access-control"><strong>say</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6TRnoSCeDRNI5LLl1EilvQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CoOCR_F7u78gr584n4lBiw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edfAW18HSII9iEvA3biUsg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YNwoUDsibcQFubkY9IJh6A.jpeg" /></figure><p><strong>Step2</strong>) We need get <strong>JSON</strong> file content as a <strong>base64</strong> string.</p><p>You can use the below command to do that.</p><blockquote>cat proxy-147413-.json | base64 &gt; google.base64.txt</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tDReooTccAzwB0hbGw6l9Q.jpeg" /></figure><p><strong>Step 3</strong>) We are going to save these credentials and repository details under <br><strong>Gitlab -&gt; Settings -&gt; CI / CD -&gt; Variables</strong>.</p><blockquote>GOOGLE_APPLICATION_CREDENTIALS_BASE64, GOOGLE_PROJECT_ID, GOOGLE_IMAGE_NAME</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6NdZVa5QFZNsGqWzhZW70A.jpeg" /></figure><p><strong>Step 4</strong>) We are going to create the <a href="https://gitlab.com/s4l1h/kaniko-google-container-registry/blob/master/.gitlab-ci.yml"><strong>.gitlab-ci.yml file</strong></a> in the project root.</p><pre>build:<br>  stage: build<br>  image:<br>    name: gcr.io/kaniko-project/executor:debug<br>    entrypoint: [&quot;&quot;]<br>  script:<br>    - export GOOGLE_APPLICATION_CREDENTIALS=/kaniko/kaniko-secret.json<br>    - echo $GOOGLE_APPLICATION_CREDENTIALS_BASE64 | base64 -d &gt; $GOOGLE_APPLICATION_CREDENTIALS<br>    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination gcr.io/$GOOGLE_PROJECT_ID/$GOOGLE_IMAGE_NAME:$CI_COMMIT_TAG<br>  only:<br>    - tags</pre><p>In this CI configuration when we push any tag to repository Gitlab CI will trigger to a job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CqcirvFK_Phon5FGP0q6QA.jpeg" /></figure><p>When the job finished. You will be able to see your container image in the <strong>Google Container Registry.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3qcxsy7_wvLBhMkTPNwag.jpeg" /></figure><h4>You can access the repositories from these addresses.</h4><p><a href="https://gitlab.com/s4l1h/kaniko-google-container-registry">https://gitlab.com/s4l1h/kaniko-google-container-registry</a></p><p><a href="https://gitlab.com/s4l1h/kaniko-amazon-elastic-container-registry">https://gitlab.com/s4l1h/kaniko-amazon-elastic-container-registry</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=889e854fb7f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Güvenlik bir ilizyondan ibarettir]]></title>
            <link>https://medium.com/@s4l1h/g%C3%BCvenlik-bir-ilizyondan-ibarettir-7c41082f2640?source=rss-43261ee2c8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c41082f2640</guid>
            <dc:creator><![CDATA[A.Kadir Mutlu]]></dc:creator>
            <pubDate>Sun, 25 Mar 2018 18:24:13 GMT</pubDate>
            <atom:updated>2018-03-25T18:24:13.132Z</atom:updated>
            <content:encoded><![CDATA[<p>When I was a hacker…</p><p>Diye başlamayacak cümle çünkü yeteri kadar ingilizce bilmiyorum hatta Türkçeyide yeteri kadar bildiğimi sanmıyorum 16 yıl okul okumama rağmen …</p><p>Çünkü aslen bir <strong>Kürdüm</strong>.Turkish language allways be my second language.(Bu cümlem sizde sıkıntı yarattıysa sizde problem vardır ve benim tek suçum <strong>dürüst</strong> olmam)</p><p>Eskiden az biraz hack ile uğraşırken ve hızlı zamanlarımdayken başımdan geçen yada insanlara verdiğim zararlardan sadece <strong>birinden</strong> bahsedeceğim.</p><p>Insanlar bildikleri kadar güvende hissederler kendilerini hani meşhur bir cümle vardır “<strong>cehalet mutluluktur</strong>“ ”diye aynen öyle.Herkes sisteminin erişilmez olduğunu untouchable (dokunulmaz) ve erişilmez olduğunu sanır.Çünkü herkes kendi biyolojik olarak ona bahşedilen beyninde düşünebildiği anlayabildiği çerçevede haklıdır.</p><p>Çocuksu ve insanı duyguların en üst seviyede olduğu bir zamanda geçiyor bu olaylar bir o kadarda egonun ve azmin tavan yaptığı bir zaman.Kafada düşünüyorsunuz “<strong>Benden hızlısı ve tehlikelisi mezarda</strong>”</p><p>Var olan programlama bilgisi ve sunucu bilgisi ile kafa ağırtan herşeyin <strong>içinden geçiyoruz</strong> yazdığımız özel <strong>tool</strong>’lar ve yöntemler ile. Kimse bilmediği ve <strong>private</strong> olduğu için <strong>fixlenemez</strong> durumdalar.Bazen başka ülkelerden arkadaşlarla <strong>exchange</strong> ediyoruz <strong>tool</strong>’ları yöntemleri fakat en önemli kural <strong>private</strong> kalması.</p><p>Örnek verecek olursam linux admin tüm portları kapatıyor aklı sıra fakat ssh ve cpanel vb.. panel portları mecbur açık kalıyor sunucuda backdoor açılamıyor diye düşünüyor fakat o portlar açık olduğu için başka bir sunucuda listening yapınca bağlanılıyor yani tam tersi şekildede bağlanılıyor.</p><p>Bir diğer güvenlik fix’i sunucuda <strong>/bin </strong>dizinindeki dosyaların çalıştırma yetkilerini alıyor fakat sunucuya işletim sisteminde çalışabilecek binary dosya yüklendiğinde çokta güzel çalışıyor <strong>eg</strong>: <strong>./ls </strong>diyip çalıştırıyorduk.</p><p>Bir diğer güvenlik problemi tüm sessionlar <strong>/tmp</strong> dizininde olduğu için uzun bir uğraş sonucunda birazda şanslıysak <strong>sessionID</strong>’ı okuyup sisteme login oluyorduk.</p><p>Bir diğer’i ; herşey kapalıysa cpanel yada plesk herneyse ordan bir <strong>cron job </strong>oluşturup istediğimiz dosyayı çalıştırıyorduk genelde her zaman yetki <strong>root</strong> oluyordu.</p><p>Zaten <strong>safe_mode</strong> saçmalığını söylemiyorum bile en aptal olanlar onlardı :)))</p><p>Özellikle litespeed’in meşhur olduğu zamanlarda <strong>File Name XSS</strong> diye birşey keşfetmiştim ve o sırada bir çok upload sitesinde bu güvenlik açığı vardı.Herkes dosyanın içeriğini kontrol ediyor fakat dosya adının güvenliğine bakmıyordu litespeed dosyaları listelediğinde aynı hatayı yapıyordu.Bildiğiniz ve gördüğünüz “<strong>index of</strong> “ ta herhangi bir dosya adını <strong>&lt;script&gt;alert(1)&lt;/script&gt;</strong> yaptığınızda <strong>xss</strong> kodu çalışıyordu.Bu yöntem ile xss kullandığımızda oldu.(http://1.1.1.1/~user/files/)</p><blockquote><strong>Bu kadar konu dışı açıklama yaptıktan sonra şimdi konuya giriş yapıyorum.</strong></blockquote><p>Güvenlik bir bir çok aşamadan oluşuyor mutlaka bir yerlerde bir <strong>kod parçacağında</strong> yada bir <strong>insan</strong>’da hata olabilir.Çünkü internette bir kullanıcı <strong>domain.com+enter tuşuna</strong> basınca bir sürü aşamadan geçiyor.Bunlardan herhangi birinde hata olması yeterli araya girmek için.</p><p>Bu hack hikayesinde <strong>problem</strong> bir insandan kaynaklandı.Bir nevi “<strong>Social Engineering Hack</strong>”.Yada tabir herneyse.I dont care…</p><p>Bir hedef var kafaya koyduğum sunucu dedicated <strong>php shell</strong> vb.. bir şekilde erişilemez.Trojan vb.. yöntemler etkisiz kalıyor mailler ve domain hack denemeleri başarısız kalıyor.</p><p>Şeytanı si.… göndereli çok oldu diye düşünüyorsunuz <strong>küçücük beyninizde </strong>kimse duramaz beni diyorsunuz fakat bazen yöntem değiştirmek gerekiyor..</p><p>Sunucu <strong>nixon</strong>(I am not sure about name) verimerkezinde barınıyor.Normalde insanlar sunucu şifrelerini unutabiliyor o zamanda <strong>ticket</strong> açıp sunucu şifrenizi <strong>sıfırlayabiliyorsunuz</strong>.Fakat herhangi bir panel bilgisine sahip olmadığımız için iş biraz daha zor olacak.Biraz araştırma sonrasında Veri Merkezinde sunucuları kurdukları vakit şifreyi <strong>nixon123</strong> yaptıklarını öğreniyoruz daha sonra ikinci aşamaya geçiyoruz ortamda stres yaratmaya ve hatalı işlem yaptırmak için bireyleri <strong>zorlamaya</strong> tabiki bunun için en iyi çözüm <strong>problem</strong> oluşturmak.Insanların büyük çoğunluğu genelde <strong>stres</strong> altında ve <strong>kızdıklarında</strong> yanlış kararlar verip <strong>yanlış</strong> hareketler yaparlar.</p><p>Elimizde olan bir kısım <strong>botnet</strong> ile sunucuya saldırı yapıyoruz tabiki sunucu erişilmez oluyor ve bazen erişilebilir sonuç itibariyle elimizde bir problem var.</p><p>Veri Merkezini(<strong>VM</strong>) telefonla arıyoruz</p><p><strong>Biz:</strong> Merhabalar sunucuma erişemiyorum sürekli kopuyor root şifremde çalışmıyor sanırım sunucum hacklenmiş .</p><p><strong>VM: </strong>Evet beyefendi görüyoruz sizin sunucudan dışarıya saldırı var.(Çünkü yaptığımız saldırı <strong>reflection</strong> saldırısı ve Veri Merkezindeki personel bunu <strong>bir bakışta</strong> anlayamaz).</p><blockquote>Benim gözümde <strong>Reflection</strong> saldırıları en tehlikeli <strong>botnet</strong> saldırılarıdır <strong>bir</strong> verip <strong>yüz</strong> alabilirsiniz bu işlem sonucunda.</blockquote><p><strong>Ben: </strong>Lütfen sunucu şifremiz sıfırlarmısınız <strong>kurulum yaptığınızdaki gibi nixon123</strong> yaparmısınız.</p><p><strong>VM: </strong>Tabi ama önce kimlik bilgileriniz gerekli bu işlemi yapabilmemiz için.</p><p><strong>Ben: </strong>Tabi kimliğim alıp geliyorum( bir süre bekletiyorum çünkü ortada kimlik yok.)</p><p><strong>Ben: </strong>Hala arıyorum ve bulamadım kimliğimi lütfen sıfırlarmısınız şifremi müşterilerim arıyorlar beni ( biraz mağdur rolünde bir ses tonu ile.)</p><blockquote><strong>Beklenen an geliyor ve personel hata yapıyor…</strong></blockquote><p><strong>VM: </strong>tamam beyefendi 5 dakika sonra şifreniz sıfırlanmış olacak .</p><p><strong>Ben: </strong>Teşekkür ederim şimdi müşterilerime cevap vermeliyim.Teşekkürler.</p><p>Aşağı yukarı 5 dakika sonra şifre sıfırlanmış oluyor ve sunucuya reset atılıyor Bizde sunucuya root kullanıcısı ile bağlanıp sunucudaki tüm datalar alınıp gerekli yerlere gerekli dosyalar yüklenmiş oluyoruz..</p><blockquote><strong>Bu hikayede burda bitmiş oluyor…Belki daha fazla güvenlik yada hack hakkında yazı yazabilirim .</strong></blockquote><p><strong><em>Büyük ihtimal bu yazdığım makalenin hiç bir gerçekliği yoktur belki hepsini uyduruyorumdur.….</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c41082f2640" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang JSON ve Interface Kullanımı]]></title>
            <link>https://medium.com/@s4l1h/golang-json-ve-interface-kullan%C4%B1m%C4%B1-cc01083210bd?source=rss-43261ee2c8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc01083210bd</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <dc:creator><![CDATA[A.Kadir Mutlu]]></dc:creator>
            <pubDate>Thu, 08 Mar 2018 17:39:17 GMT</pubDate>
            <atom:updated>2018-03-08T17:40:09.567Z</atom:updated>
            <content:encoded><![CDATA[<p>Merhabalar,</p><p>Golang’te json data formatında işlemlerini yaparken ana kütüphanelerden olan <a href="https://golang.org/pkg/encoding/json">https://golang.org/pkg/encoding/json</a> kullanabilirsiniz. <br>Öncelikle basit bir örnek yapacağız daha sonra bu kütüphane bize yeterli gelmediğinde araya girip <strong>interface</strong> kullanacağız ve mutluluğa ulaşacağız.</p><p>Basit bir <strong>person</strong> objesi tanımlayalım ve <strong>json</strong>’a çevirelim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac668c224ce98138610d93c5b2116c23/href">https://medium.com/media/ac668c224ce98138610d93c5b2116c23/href</a></iframe><p>Görüldüğü üzere verdiğimiz obje olduğu gibi json’a çevrildi.Struct’ın json tagını değiştirerek istediğimiz gibi <strong>json field name </strong>değiştirdik satır <strong>11</strong>&#39;den bahsediyorum.</p><p>Bir sonraki aşamada <strong>company</strong> objesi ekleyelim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77150d24f07e40cbf544a21af1a5933b/href">https://medium.com/media/77150d24f07e40cbf544a21af1a5933b/href</a></iframe><p>Görüldüğü üzere <strong>company</strong> objesine <strong>persons</strong> eklendi herşey çok güzel bir şekilde çalışıyor.</p><p>Gel gelelim birde <strong>person</strong> objesine <strong>company</strong> özelliği eklemeye çünkü program içinde bir yerlerde <strong>person</strong>’ın <strong>company</strong> adına ulaşmak isteyebiliriz.</p><p>Kodumuzu güncelleyelim.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36a9ee9902adc0e4c1aadc90874c0590/href">https://medium.com/media/36a9ee9902adc0e4c1aadc90874c0590/href</a></iframe><h3>Oppss….</h3><p>Kodumuz aşağıdaki gibi bir hata verecektir çünkü sürekli bir döngü halinde pointer pointerı takip edecek bir döngü oluşacak.</p><pre> ~/go/src/github.com/s4l1h/jsonTest   v3 ●  go run main.go  <br>                       <br>runtime: goroutine stack exceeds 1000000000-byte limit<br>fatal error: stack overflow</pre><pre>runtime stack:<br>runtime.throw(0x10e0fb1, 0xe)<br>        /usr/local/Cellar/go/1.10/libexec/src/runtime/panic.go:619 +0x81</pre><p>Hatırlarsanız “person → company” objesine “company’de → person” objesine erişebiliyor. json kütüphanemizde bu döngüde takılıp kalıyor belirli bir limitten sonrada hata dönderiyor.</p><p>Neyseki golang’in json kütüphanesinin interface özelliğini kullanarak bu problemi aşabiliyoruz.</p><p><a href="https://golang.org/pkg/encoding/json/#Marshal">Golang json</a> dökümantasyonunda yazıldığı üzere bir objeyi <strong>json</strong>’a çevirirken <a href="https://golang.org/pkg/encoding/json/#Marshal"><strong>json.Marshal</strong></a><strong> </strong>fonksiyonunu kullanırsanız golang kütüphanemiz öncelikle objenin <strong>MarshalJSON</strong> adında bir fonksiyona sahip olup olmadığına bakıyor eğer bu isimde bir fonksiyona sahipse bu fonksiyonu çalıştırıyor.</p><p>Bizde person objemize bu fonksiyonu ekleyelim ve sonuca bakalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3238d942a70773664a602755cca99993/href">https://medium.com/media/3238d942a70773664a602755cca99993/href</a></iframe><p>Görüldüğü üzere json kütüphanesi söylenildiği şekilde bizim yazdığımız <strong>MarshalJSON</strong> fonksiyonunu çalıştırdı.Aynı şekilde bir json objesini <strong>decode</strong> ederkende <strong>UnmarshalJSON</strong> kullanarak json decode edilirken dataya müdahale edebiliriz.</p><p><strong>Pointer</strong> kullanılmasaydı direk <strong>değer</strong> verilseydi <strong>Company</strong> objesine json dönüştürmelerinde bir sıkıntı olmayacaktı fakat <strong>pointer</strong> nimetlerinden yararlanmak istiyorsak kod yazarken bazen bu tür sıkıntılarla karşı karşıya gelebiliriz.Objenin adresini göndermek varken neden objenin kendisiniz gönderelim?</p><p>Yukarıdaki cümleyi kodla açıklayalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3961a33ff76f4acdcdeafcbd307a7580/href">https://medium.com/media/3961a33ff76f4acdcdeafcbd307a7580/href</a></iframe><p>Bu problemle <strong>golang</strong> ile <strong>ACL</strong> kütüphanesi yazarken karşılaştım <a href="https://github.com/s4l1h/acl/blob/master/perm.go#L41"><strong>bu linkten</strong></a><strong> </strong>ACL kütüphanesinin ilgili satırına erişebilirsiniz.</p><p>Yukardaki kodlar da <strong>bilerek</strong> bazen <strong>json</strong> <strong>tagını</strong> değiştirip eklemeler yaptım.Çıktılara bakıp daha iyi anlayabilirsiniz böylelikle</p><p>JSON tag’de “<strong>-</strong>” kullanırsanız kütüphane o fieldi ignore edecek kullanmayacaktır. Eğer “<strong>omitempty</strong>” kullanırsanız; obje field’ı bir değere sahip değilse <strong>null</strong> yada <strong>boş</strong> yerine json’da o fielde ait çıktı oluşturmayacaktır fakat field bir değere sahipse json çıktısında görünecektir.</p><p>Have a nice day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc01083210bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Kullanımı]]></title>
            <link>https://medium.com/@s4l1h/terraform-kullan%C4%B1m%C4%B1-b9719e96d609?source=rss-43261ee2c8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9719e96d609</guid>
            <category><![CDATA[debian]]></category>
            <category><![CDATA[digitalocean]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[A.Kadir Mutlu]]></dc:creator>
            <pubDate>Mon, 27 Nov 2017 19:12:13 GMT</pubDate>
            <atom:updated>2017-11-27T19:31:42.226Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.terraform.io/">Terraform</a> <a href="https://www.hashicorp.com/">hashicorp</a> firmasının sunucu alt yapınızı kod olarak yazıp planlayıp oluşturmanızı sağlayan bir yazılım.Web sayfalarında şu şekilde yazıyor.</p><blockquote><strong>Write, Plan, and Create Infrastructure as Code</strong></blockquote><p>Olaya girmeden önce neden terraform kullanacağız onu anlayalım.Müşteriden gelen istek şu; bir anda <strong>50</strong> tane sunucu oluşturulup içine <a href="http://www.squid-cache.org/"><strong>squid</strong></a><strong> </strong>kurulması ve <a href="http://www.squid-cache.org/"><strong>squid</strong></a><strong> </strong>ayarlarının yapılması isteniyor haliyle işleri bittiğinde de silmek istiyorlar.</p><p>Müşteri bu işlem için <a href="https://www.digitalocean.com/">digitalocean</a> <a href="https://www.vultr.com/">vultr</a> <a href="https://www.linode.com/">linode</a> gibi AWS,Azure ve GCP’ye nazaran daha ucuz cloud sunucu hizmeti veren firmaları kullanmak istiyor.</p><p>Bu işlemi panelden tek tek yapmak ne kadar zaman alır hesaplamayı size bırakıyorum.</p><p>Legacy kodumuzda bu firmaların her birinin api’ını kullanarak <strong>sunucuları kurup </strong>daha sonra <a href="https://www.ansible.com/"><strong>ansible</strong></a> ile sunuculara squid kurup ayar dosyalarını yazıyorduk ve bunu her cloud provider için tekrar yazmamız gerekiyordu.Çünkü her firmanın api’ı bir birinden farklıydı bu nedenle bu işlemi tek bir yazılım ile çözmek için <strong>terraform</strong> ile yazmaya karar verdik.</p><p>Eski koddan bir örnek.Linode python kütüphanesini ile sunucu oluşturuyor.Bunlar bir dosyaya yazılıyor sonra <strong>ansible-playbook -i proxy/hosts proxy/proxy.yml</strong> gibi bir komutla proxy’ler kuruluyordu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oe-678LFqAmIUeVwrrwhpw.png" /></figure><p><em>Makale yazarken elimden geldiğince </em><strong><em>ana</em></strong><em> </em><strong><em>mantığı</em></strong><em> anlatmaya çalışıyorum.Ne kadar başarılı oluyorum tartışılır.Anlamadığınız kısımları </em><a href="https://www.terraform.io/intro/index.html"><em>terraform dökümantasyon</em></a><em> sayfasından okuyabilirsiniz.</em></p><h3>Kurulum</h3><p><a href="https://www.terraform.io/intro/getting-started/install.html">https://www.terraform.io/intro/getting-started/install.html</a> adresinden işletim sisteminize uygun kurulum dosyasına erişebilirsiniz.. <strong>Mac</strong> kullanıyorsanız <strong><em>brew install terraform</em></strong> yazarak basitçe kurabilirsiniz.</p><h3>Terraform da temel bir kaç şeyden bahsedeceğim.</h3><p><a href="https://github.com/hashicorp/hcl"><strong>HLC</strong></a>: Yapılandırma dosyaları bu dilde yazılıyor.Terraform JSON’de destekliyor fakat dökümantasyon ve örnekler hlc olarak yazılmış.</p><p>Terraform’da <strong>HLC</strong>’yi .<strong>tf</strong> uzantılı dosyalara yazıyoruz.Terraform bunu algılıyor.</p><p><a href="https://www.terraform.io/docs/providers/index.html"><strong>Provider</strong></a> : Türkçeye çevirecek olursak sağlayıcı anlamında örnek aws,linode,azure,vultr bunlar sağlayıcılar.Bir çok firma kendi provider’ını yazmış durumda unoffical olanlarda bulunuyor isterseniz kendinizde provider yazabilirsiniz.Terraform’da provider kavramı sadece <strong>VM</strong> sağlayan değil, <strong>kaynak(</strong><em>resource</em><strong>)</strong> sağlayan anlamındadır örnek vermek gerekirse cloudflare’e ait bir provider bulunuyor.</p><pre># provider.tf dosyası<strong><br>provider</strong> &quot;digitalocean&quot; {<br>   token = &quot;${var.do_token}&quot; #providerin ihtiyacı olan token.<br>}</pre><p><a href="https://www.terraform.io/docs/configuration/resources.html"><strong>Resource</strong></a> : Kaynak demek hatırlarsanız, kaynakları da provider’ler sağlıyorlardu.</p><p>Basitçe : <strong>digitalocean</strong> bir provider ve <strong>digitalocean_droplet</strong> adında bir resource sahip.Bu resource yardımıyla do’da sunucu oluşturabilirsiniz.</p><p>Örnek : <strong>debian-9 </strong>imajına sahip ismi <strong>squid</strong> olan <strong>lon1</strong>’da <strong>512mb</strong>’lik bir sunucu oluşturur.</p><pre># squid.tf dosyası<strong><br>resource</strong> &quot;<strong>digitalocean_droplet</strong>&quot; &quot;<strong>squid</strong>&quot; {<br>  image = &quot;debian-9-x64&quot;<br>  name=&quot;squid&quot;<br>  region = &quot;lon1&quot;<br>  size = &quot;512mb&quot;<br>}</pre><p><a href="https://www.terraform.io/docs/configuration/outputs.html"><strong>Output</strong></a><strong> Variables</strong>: variables ve resources sonucu oluşan çıktılara erişebilirsiniz.Örnek verecek olursak sunucuları oluşturduktan sona bize ip listesini veren bir output yazabiliriz.</p><pre>#output.tf dosyası<br><strong>output</strong> &quot;ips&quot; {<br>  value = &quot;${digitalocean_droplet.squid.ipv4_address}&quot;<br>}</pre><p><em>Terminalde </em><strong><em>terraform output ips</em></strong><em> yazarak çıktı alabilirsiniz</em></p><p><a href="https://www.terraform.io/docs/configuration/variables.html"><strong>Input</strong> <strong>Variables</strong></a> : girdi olan değişkenler.Bunlar genelde api lere erişim için token’lar, image tipleri, region gibi değişkenler oluyor.Örnek : debian-9-x64,lon1,512mb gibi..Değişkeni tanımlarken <strong>default</strong> neden gerekli lütfen dökümantasyonu okuyunuz yada <strong>default</strong> olmadan çalıştırarak önizleyiniz.</p><pre># variables.tf dosyası<strong><br>variable</strong> &quot;do_token&quot; {<br>  <em>default =  &quot;uzuncabirtoken&quot;<br></em>}<br><strong>variable</strong> &quot;pub_key&quot; {<br>  <em>default = &quot;./id_rsa.pub&quot;<br></em>}<br><strong>variable</strong> &quot;pvt_key&quot; {<br>  <em>default=&quot;./id_rsa&quot;<br></em>}<br><strong>variable</strong> &quot;ssh_fingerprint&quot; {}</pre><p>Ayarları istersek <strong>.tfvars</strong> dosya formatında da yazabiliriz.</p><blockquote>Terraform çalıştığı dizindeki <strong>terraform.tfvars</strong> dosyasını ve <strong>*.auto.tfvars</strong> dosyalarını otomatik olarak yükler.</blockquote><pre><em># ssh.auto.tfvars dosyası<br></em>pub_key = &quot;./id_rsa.pub&quot;</pre><pre>pvt_key = &quot;./id_rsa&quot;</pre><pre>ssh_fingerprint = &quot;MD5:36:76:66:81:33:8e:b2:cb:7c:05:41:10:87:dd:3f:26&quot;</pre><p><strong>tfvars</strong> dosyalarını CLI’dan dosya ismi de vererek yükleyebilirsiniz: -var-file<strong>=</strong>foo.tfvars</p><p>Son olarakta variables’ları isterseniz cli’dan aktarabilirsiniz:-var foo<strong>=</strong>bar</p><p>Terraform işini yapabilirmesi için <strong>init</strong> edilmesi gerekiyor init edildiğinde ona gereken bağımlıkları indirecektir.Örnek bir provider kullandığınızda onu indirecektir ve <strong><em>her yeni provider kullandığınızda tekrardan init çalıştırmanız gerekir.</em></strong></p><p>Bu kadar ön bilgi verdikten sonra problemi çözelim öncelikle bir ssh key oluşturalım var olan kendi ssh keyimi kullanmayacağım çünkü kodu paketleyip vereceğim.Müşteriye ssh key oluştur demem gerekmeyecek yada bundan kaynaklı bir problem çıkmayacak.<br><strong>ssh-keygen -t rsa -f ./id_rsa</strong> komutu ile bulunduğum dizin de public ve private key’i oluşturalım.</p><p><strong>Passphrase</strong>’i es geçiyorum çünkü her kullanımda şifre isteyecek yada <strong>ssh-agent</strong>’e eklemek gerekecek uğraşmaya gerek yok.</p><pre>~/Desktop/terraform_do<strong><br></strong>▶ <strong>ssh-keygen -t rsa -f ./id_rsa</strong><br>Generating public/private rsa key pair.<br>Enter passphrase (empty for no passphrase):<br>Enter same passphrase again:<br>Your identification has been saved in ./id_rsa.<br>Your public key has been saved in ./id_rsa.pub.<br>The key fingerprint is:<br>SHA256:M1coSFqGSUJDJDosNYsa4IRdN9vDsLGXcbjZ0KTRipQ macos@macOS-MacBook-Pro.local<br>The key&#39;s randomart image is:<br>+---[RSA 2048]----+<br>|+*OoooO.o=o      |<br>|B+.=o*E@o*o.     |<br>|*o. ..=.O*. .    |<br>|oo    ..+o..     |<br>|.       S .      |<br>|         +       |<br>|                 |<br>|                 |<br>|                 |<br>+----[SHA256]-----+</pre><pre><strong>~/Desktop/terraform_do</strong><br>▶ ls -la<br>total 16<br>drwxr-xr-x   4 macos  staff   136 Nov 27 19:19 .<br>drwx------+ 77 macos  staff  2618 Nov 27 19:17 ..<br>-rw-------   1 macos  staff  1679 Nov 27 19:19 id_rsa<br>-rw-r--r--   1 macos  staff   411 Nov 27 19:19 id_rsa.pub<br><strong>~/Desktop/terraform_do</strong><br>▶ <strong>ssh-keygen -E md5 -lf ./id_rsa | awk &#39;{print $2}&#39;</strong><br>MD5:f2:73:1b:f7:4a:54:2e:e0:f4:84:f8:b2:e6:fd:75:71</pre><p>DO paneline girip <a href="https://cloud.digitalocean.com/settings/security"><strong>security</strong></a> kısmına ssh keys kısmına <strong>public keyi</strong> (id_rsa<strong>.pub</strong>) ekliyoruz.</p><p>Daha sonra panelden <a href="https://cloud.digitalocean.com/settings/api/tokens"><strong>token</strong></a> oluşturuyoruz.</p><blockquote>Lütfen oluşturduğunuz <strong>token’ı</strong> kaydedin bir daha göremeyeceksiniz.</blockquote><p><strong>squid.tf</strong> adında bir dosya oluşturuyoruz ve içine önce değişkenleri tanımlıyoruz ve daha sonra provideri tanımlıyoruz.</p><pre># squid.tf dosyası</pre><pre><strong>variable</strong> &quot;do_token&quot; {<br>  default =  &quot;Buraya Oluşturduğunuz TOKEN YAZILACAK&quot;<br>}</pre><pre><strong>variable</strong> &quot;pub_key&quot; {<br>  default = &quot;./id_rsa.pub&quot;<br>}</pre><pre><strong>variable</strong> &quot;pvt_key&quot; {<br>  default=&quot;./id_rsa&quot;<br>}</pre><pre><strong>variable</strong> &quot;ssh_fingerprint&quot; {<br>  default=&quot;f2:73:1b:f7:4a:54:2e:e0:f4:84:f8:b2:e6:fd:75:71&quot;<br>}<br><strong>provider</strong> &quot;digitalocean&quot; {<br>  token = &quot;${var.do_token}&quot;<br>}</pre><p><strong>terraform init</strong> dediğimiz vakit provider’ı indirecek ve <strong>.terraform</strong> klasörünü oluşturacak</p><pre>▶ <strong>terraform init</strong></pre><pre>Initializing provider plugins...<br>- Checking for available provider plugins on <a href="https://releases.hashicorp.com/">https://releases.hashicorp.com</a>...<br>- Downloading plugin for provider &quot;digitalocean&quot; (0.1.2)...</pre><pre>....<br>~/Desktop/terraform_do<br>▶ <strong>tree</strong><br>.<br>├── id_rsa<br>├── id_rsa.pub<br>└── squid.tf<br>~/Desktop/terraform_do<br>▶ <strong>tree .terraform</strong><br>.terraform<br>└── plugins<br>    └── darwin_amd64<br>        ├── lock.json<br>        └── terraform-provider-digitalocean_v0.1.2_x4</pre><pre>2 directories, 2 files</pre><p>Şimdi sırada oluşturacağımız resource tanımlayalım.</p><p><strong>digitalocean_droplet</strong> kullandığımız resource.</p><p><strong>squid</strong> ise resource adı.</p><p>Aynı zamanda <strong>output</strong>’uda ekleyelim. İşaret ettiği isimlendirmeye dikkat edelim.</p><pre>resource &quot;<strong>digitalocean_droplet</strong>&quot; &quot;<strong>squid</strong>&quot; {<br>    image = &quot;debian-9-x64&quot; #imaj<br>    name=&quot;squid&quot; # Do panelinde görünecek ad<br>    region = &quot;lon1&quot;<br>    size = &quot;512mb&quot;<br>    private_networking = true<br>    ssh_keys = [<br>      &quot;${var.ssh_fingerprint}&quot; # droplet&#39;e eklenecek ssh key<br>    ]<br>}<br><strong>output</strong> &quot;ip&quot; {<br>   value = &quot;${<strong>digitalocean_droplet</strong>.<strong>squid</strong>.<strong>ipv4_address</strong>}&quot;<br>}</pre><h3>Plan</h3><p>Şimdi <strong>terraform plan</strong> yazarak <strong>planı</strong> görelim.aşağıdakine benzer bir çıktı verecektir.Görüldüğü üzere 1 adet ekleme yapacağını söylüyor.</p><pre>▶ <strong>terraform plan</strong><br>Refreshing Terraform state in-memory prior to plan...<br>....</pre><pre>Terraform will perform the following actions:</pre><pre>+ digitalocean_droplet.squid<br>      image:                &quot;debian-9-x64&quot;<br>....<br>      ssh_keys.0:           &quot;f2:73:1b:f7:4a:54:2e:e0:f4:84:f8:b2:e6:fd:75:71&quot;</pre><pre>Plan: <strong>1 to add</strong>, 0 to change, 0 to destroy.</pre><h3>Uygulama</h3><p><strong>terraform apply</strong> yazarak uygulayalım bize işlemi yapmak istiyormusunuz diye soracak <strong>yes</strong> diyip devam ediyoruz.</p><pre>▶ <strong>terraform apply</strong></pre><pre>....</pre><pre>Terraform will perform the following actions:</pre><pre>+ digitalocean_droplet.squid<br>....</pre><pre>digitalocean_droplet.squid: Still creating... (10s elapsed)<br>digitalocean_droplet.squid: Still creating... (20s elapsed)<br>digitalocean_droplet.squid: Creation complete after 29s (ID: 72709799)</pre><pre>Apply complete! Resources: 1 added, 0 changed, 0 destroyed.</pre><pre>Outputs:</pre><pre>ip = 46.101.1.219</pre><p>Paneldeki görüntüde şu şekilde olacaktır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TErq-zsZJFFH9bWDZTwEvw.png" /></figure><h3>Output</h3><pre>▶ terraform output <strong>ip</strong><br>46.101.1.219</pre><p><strong>terraform output ip</strong> yazarak tanımladığız <strong>ip</strong> output değişkenine erişebiliriz.</p><p>Aşağıdaki komut ile sunucuya bağlanabilirsiniz.</p><pre>▶ ssh root@$(<strong>terraform output ip</strong>) <strong>-i</strong> ./id_rsa</pre><h3>Silme</h3><p>Şimdi oluşturduğumuz dropleti <strong>terraform destroy</strong> yazarak silelim. İşlem onayı için <strong>yes</strong> yazıp devam ediyoruz ve işlem sonucunda droplet silinmiş oluyor.</p><pre>▶ <strong>terraform destroy</strong><br>digitalocean_droplet.squid: Refreshing state... (ID: 72709799)<br>....</pre><pre>Terraform will perform the following actions:</pre><pre>- digitalocean_droplet.squid</pre><pre>Plan: 0 to add, 0 to change, 1 to destroy.</pre><pre>Do you really want to destroy?<br>  Terraform will destroy all your managed infrastructure, as shown above.<br>  There is no undo. Only &#39;yes&#39; will be accepted to confirm.</pre><pre>Enter a value: yes</pre><pre>digitalocean_droplet.squid: Destroying... (ID: 72709799)<br>digitalocean_droplet.squid: Still destroying... (ID: 72709799, 10s elapsed)<br>digitalocean_droplet.squid: Destruction complete after 12s</pre><pre>Destroy complete! Resources: 1 destroyed.</pre><h3>Yazılım Kurulumu</h3><p>Sıradaki işlem sunucuya squid <strong>kurmak</strong> ve ayar dosyalarını <strong>kopyalamak</strong>.Öncelikle <strong>connection</strong> tanımlayıp terraform’un sunucuya bağlanabilmesini sağlıyoruz.<strong>private_key</strong> kısmında <strong>file</strong> için lütfen burayı okuyunuz.<a href="https://www.terraform.io/docs/configuration/interpolation.html">https://www.terraform.io/docs/configuration/interpolation.html</a></p><pre>connection {<br>      user = &quot;root&quot;<br>      type = &quot;ssh&quot;<br>      private_key = &quot;${<strong>file</strong>(var.pvt_key)}&quot;<br>      timeout = &quot;2m&quot;<br>}</pre><p>Daha sonra <a href="https://www.terraform.io/docs/provisioners/index.html"><strong>provisioner’i</strong></a> ayarlıyoruz. işlemler yazılma sırasına göre çalışıyor. <strong>file</strong> ile local’de bulunan <strong>squid.conf </strong>dosyasını sunucudaki <strong>/etc/squid/squid.conf</strong> dizine taşıyoruz.</p><p><strong>remote-exec</strong> ile sunucuda komut çalıştırıyoruz.Bilinen klasik <strong>apt</strong> komutları. ve squid’in sunucuya kopyaladığımız yeni ayarları tanıması için <strong>restart</strong> atıyoruz.</p><p>Daha sonra sunucu ip adresini <strong>ip.txt</strong> dosyasına yazması için bir <strong>local-exec</strong> çalıştırıyoruz.</p><pre><strong>connection</strong> {<br>      user = &quot;root&quot;<br>      type = &quot;ssh&quot;<br>      private_key = &quot;${<strong>file</strong>(<strong>var.pvt_key</strong>)}&quot;<br>      timeout = &quot;2m&quot;<br>}<br>provisioner &quot;<strong>remote-exec</strong>&quot; {<br>        inline = [<br>        &quot;export PATH=$PATH:/usr/bin&quot;,<br>        # install nginx<br>        &quot;sudo apt-get update&quot;,<br>        &quot;sudo apt-get -y install ntp curl htop squid&quot;<br>        ]<br>}<br>provisioner &quot;<strong>file</strong>&quot; {<br>      source      = &quot;squid.conf&quot;<br>      destination = &quot;/etc/squid/squid.conf&quot;<br>}<br>provisioner &quot;<strong>remote-exec</strong>&quot; {<br>      inline = [<br>        &quot;systemctl restart squid&quot;<br>      ]<br>}<br>provisioner &quot;<strong>local-exec</strong>&quot; {<br>      command=&quot;rm ips.txt&quot;  <em># eski ip.txt dosyasını sil<br>      </em><strong>on_failure</strong> = &quot;continue&quot; <em># hata oluşursada devam et( dosya yoksa hata verecek.)<br></em>}<br>provisioner &quot;<strong>local-exec</strong>&quot; {<br>      command=&quot;echo ${<strong>self.ipv4_address</strong>} &gt;&gt; ips.txt&quot;<br>}</pre><p>Eğer birden fazla sunucu oluşturmak istiyorsak.yapmamız gereken.</p><p><strong>resource</strong> kısmına parametre olarak count eklemek.Aşağıdaki örnekte sayıyı 10 belirliyoruz.Aynı zamanda output’uda değişmemiz gerekecektir.Çünkü artık <strong>digitalocean_droplet.squid.ipv4_address</strong> adında bir değişken bulunmuyor onun yerine <strong>digitalocean_droplet.squid </strong>değişkeni array dönderiyor.</p><p>digitalocean_droplet.squid.<strong>0</strong>.ipv4_address</p><p>digitalocean_droplet.squid.<strong>1</strong>.ipv4_address</p><p>gibi…</p><p>Fakat bu değişkeni direk list yapabiliyoruz <strong>output</strong> için <strong><em>yıldıza dikkat edin.</em></strong></p><p>Aynı zamanda <strong>count.index</strong>’ine de erişebiliriz.ve droplet adına ekleme yapabiliriz.</p><pre><strong>output</strong> &quot;ip&quot; {<br>  value = &quot;${digitalocean_droplet.squid.<strong>*</strong>.ipv4_address}&quot;<br>}<strong><br>resource</strong> &quot;digitalocean_droplet&quot; &quot;squid&quot; {<br>   <strong>count=10<br></strong>   image = &quot;debian-9-x64&quot;<br>   name=&quot;squid-<strong>${count.index}</strong>&quot;</pre><p>Terraform output sonucu</p><pre>~/Desktop/terraform_do<br>▶ <strong>terraform output ip</strong><br>138.68.191.74,<br>138.68.162.204,<br>139.59.186.43,<br>46.101.76.137,<br>46.101.74.23,<br>139.59.179.111,<br>46.101.73.160,<br>139.59.185.134,<br>188.166.151.150,<br>138.68.160.12</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZju_TtaEnkBHh9R83Slwg.png" /></figure><h3>Benden bu kadar size kolay gelsin..</h3><p>Örnek kodlar için <strong>gist</strong> oluşturdum.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/311596a7845cc69cfc80becc22c73b57/href">https://medium.com/media/311596a7845cc69cfc80becc22c73b57/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9719e96d609" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang ve kütüphane seçimi]]></title>
            <link>https://medium.com/@s4l1h/golang-ve-k%C3%BCt%C3%BCphane-se%C3%A7imi-9ccfe186f966?source=rss-43261ee2c8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ccfe186f966</guid>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[A.Kadir Mutlu]]></dc:creator>
            <pubDate>Sat, 28 Oct 2017 22:51:02 GMT</pubDate>
            <atom:updated>2017-10-29T08:37:49.849Z</atom:updated>
            <content:encoded><![CDATA[<p>Golang ile yazdığım bir projede bazı kütüphanelere ihtiyacım vardı localde bulunuyordular bu gün itibariyle yayınladım.<br>Kütüphanelerde dökümantasyon ve <strong>test eksiği</strong> olabilir.<br>Yeni yayınladığım kütüphaneler.<br><a href="https://github.com/s4l1h/acl">https://github.com/s4l1h/acl</a><br><a href="https://github.com/akmyazilim/translator">https://github.com/akmyazilim/translator</a><br><a href="https://github.com/akmyazilim/flash">https://github.com/akmyazilim/flash</a><br><a href="https://github.com/akmyazilim/event">https://github.com/akmyazilim/event</a><br><a href="https://github.com/akmyazilim/assetfile">https://github.com/akmyazilim/assetfile</a></p><p>Aşağıda basitçe kullandığım kütüphaneleri ve sebeplerini anlatmak istiyorum.<br>Yazdığım proje web tabanlı çok dilli çalışan bir otomasyon.(proje bitmedi henüz.)<br>Genel itibariyle çoklu dil’e uygun modüler ve esnek çalışabilen kütüphaneler seçtim.</p><p>Database ve ORM kısmında : <a href="https://github.com/jinzhu/gorm">https://github.com/jinzhu/gorm</a><br>En kapsamlı orm fakat <strong>%10 performans</strong> kaybı var xorm,pgx vs.. benzeri kütüphanelerle karşılaştırdığımda.<strong> auto migrate</strong> özelliği çok iyi.</p><p>Yetki yönetimi için: <a href="https://github.com/s4l1h/acl">https://github.com/s4l1h/acl</a><br>Sistem modüler olduğu için modüller,gruplar ve yetkiler bulunuyor.<br>Örnek: <strong>Modül:</strong>Blog, <strong>Üye Grubu:</strong> editor,admin,superadmin <strong>Yetki:</strong> create,update,delete<br>Tüm yetkileri vermek için wilcard desteği yok şimdilik.Yazdığım bir <strong>middleware</strong> ile otomatik yetki kontrolü yapıyor./blog/<strong>Read</strong>/1 yetki sormazken. /blog/<strong>create</strong> yetki soruyor.<strong>Action</strong> kısmındaki büyük küçük harfe bakıyor.Böylelikle <strong>router</strong> tarafında yetki <strong>check</strong> ediliyor.</p><p>Template kısmında: <a href="https://github.com/flosch/pongo2">https://github.com/flosch/pongo2</a><br>Neden seçtim? <strong>jinja2</strong> synax olduğu için .Okuması yazması kolay.Layout oluşturup kullanmak kolay.</p><p>Routing için: <a href="https://github.com/labstack/echo">https://github.com/labstack/echo</a><br> <strong>route name</strong> seçeneği var diğer bir çoğunda yok <strong>gorilla</strong> hariç</p><p>Config yönetimi için : <a href="https://github.com/spf13/viper">https://github.com/spf13/viper</a><br><strong>yaml</strong> ile çok iyi çalışıyor.Ayarlara <strong>config.db.host</strong> gibi erişebiliyorsunuz.Ayar dosyalarını birleştirebiliyorsunuz <strong>merge</strong></p><p>Form validator için: <a href="https://github.com/go-playground/validator">https://github.com/go-playground/validator</a><br>Çok detaylı bir çekilde validation hatalarını alabiliyorsunuz.Embeding destekliyor.(bir objeyi <strong>embed</strong> ederseniz onuda algılıyor)<br><strong>Çok dilli</strong> olan sistemde hatayı yazdırmak daha kolay <strong>translate</strong> kütüphanesiyle senkronize çalışıyor.</p><p>Form bind için : <a href="https://github.com/go-playground/form">https://github.com/go-playground/form</a><br><strong>embeding</strong> destekliyor <strong>pointer</strong>’de problem çıkarmıyor.Nested datalarda sıkıntı çıkarmadı.</p><p>Form datalarını temizleme için : <a href="https://github.com/leebenson/conform">https://github.com/leebenson/conform</a><br>Ayarları struct’ın <strong>tag</strong>’den okuyabiliyor</p><p>Template Dosya Yönetimi için : <a href="https://github.com/akmyazilim/assetmanager">https://github.com/akmyazilim/assetmanager</a><br>sistem modüler olduğu için dosya yolunu istediğim gibi almam gerekiyordu.<strong>userModule:/create.html </strong>gibi.<br>Aynı zamanda dosyaları birleştirebiliyorsunuz.(<strong>merge</strong>)</p><p>Js ve css Yönetimi için : <a href="https://github.com/akmyazilim/assetfile">https://github.com/akmyazilim/assetfile</a><br>template kımsında css ve js ekleyip bunları eklenme sırası göre gösterebiliyorsunuz.Jquery <strong>önce</strong> yüklenmeli <strong>sonra</strong> pluginler gibi gibi.</p><p>Session Yönetimi için : <a href="https://github.com/alexedwards/scs">https://github.com/alexedwards/scs</a><br>birden fazla <strong>store</strong> destekliyor memory,redis,mysql vs..</p><p>Loglama İçin : <a href="https://github.com/sirupsen/logrus">https://github.com/sirupsen/logrus</a><br>Community desteği iyi</p><p>Debug için : <a href="https://github.com/sanity-io/litter">https://github.com/sanity-io/litter</a><br><strong>spew</strong> kütüphanesinden daha <strong>okunaklı</strong> çıktı veriyor.</p><p>Translation için: <a href="https://github.com/akmyazilim/translator">https://github.com/akmyazilim/translator</a><br>birden fazla dil dosyası ekleyebiliyorsunuz bunları birleştiriyor.(Her modülün kendine has dil dosyası var.)<br><strong>Dosya adına göre</strong> ekleme yapıyor.Örnek <strong>tr-TR.yaml</strong> dosyasını <strong>tr-TR</strong>’ye ekliyor.<strong>en-US.yaml</strong> dosyasındaki kayıtlarıda <strong>en-US</strong>’a.</p><p>Event için: <a href="https://github.com/akmyazilim/event">https://github.com/akmyazilim/event</a><br>Basit bir yazılım ; bir olayı kaydedip istediğiniz bir yerde çalıştırıyorsunuz.<br>Örnek: Proje’de port dinlenmeden hemen önce menüler çekilsin ve cachelensin.</p><p>Dil dosyalarını <strong>yaml</strong> formatında tutuyorum yazımı ve taşıması kolay oluyor.<br>Grid için <a href="https://www.jeasyui.com/"><strong>easyui</strong></a> kullandım (dataları parse etmek için küçük bir kütüphane yazdım yayınlamaya hazır değil henüz.)<br><strong>Tree</strong> ve <strong>grid</strong> kütüphanesi çok esnek.</p><p>Database tarafında <strong>postgresql’i</strong> seçtim sebebi <strong>json</strong> ve <strong>transaction</strong> desteği olması.</p><p>Editör olarak <a href="https://code.visualstudio.com/"><strong>vscode</strong></a> seçtim.Golang eklentisi içinde <a href="https://marketplace.visualstudio.com/items?itemName=lukehoban.Go">https://marketplace.visualstudio.com/items?itemName=lukehoban.Go</a><br>Değişkenin üzerine gelince tipini ve istediğinizde source kısmına gidebiliyorsunuz.Static type bir dil’de bu yazım hatalarını azaltıyor.<br><strong>Debugger</strong> için: <a href="https://github.com/derekparker/delve"><strong>delve</strong></a></p><p>Template dosyalarını <strong>renklendirme</strong> için vscode’ye <a href="https://marketplace.visualstudio.com/items?itemName=bibhasdn.django-html">https://marketplace.visualstudio.com/items?itemName=bibhasdn.django-html</a> bu eklentiyi kurabilirsiniz.<br>Kod formatlama için’de bunu <a href="https://marketplace.visualstudio.com/items?itemName=HexcodeTechnologies.vscode-prettydiff">https://marketplace.visualstudio.com/items?itemName=HexcodeTechnologies.vscode-prettydiff</a></p><p>bir modül şu şekilde görünüyor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*CXong94JD_aGtx9lA3o9pw.png" /></figure><blockquote>Modüller <strong>init()</strong> fonksiyonu ile sisteme dahil oluyorlar.<br><a href="https://www.google.com.tr/search?q=golang+init"><strong>golang init</strong></a></blockquote><p><strong>Not</strong>: Yazım hataları ve anlatım bozuklukları olabilir.Vakit buldukça düzelteceğim.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ccfe186f966" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang Interface]]></title>
            <link>https://medium.com/@s4l1h/golang-interface-9182db7ca5d3?source=rss-43261ee2c8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9182db7ca5d3</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[A.Kadir Mutlu]]></dc:creator>
            <pubDate>Sun, 12 Mar 2017 21:45:04 GMT</pubDate>
            <atom:updated>2017-03-12T21:45:04.810Z</atom:updated>
            <content:encoded><![CDATA[<p>Golang Interface kavramı</p><p>Merhabalar,</p><p>Golang’a yeni başlayanların anlamakta güclük çektikleri bir konudan bahsedeceğim oda interface kavramı.</p><p>Eğer başka bir dilde programlama ile uğraşmışsanız interface kavramına yabancı değilsinizdir.</p><p>Programlama için Interface nedir sorusuna türkçe cevap verecek olursak.</p><p>“Kendisini kullanacak sınıflar için yerine getirmeleri gereken metodları belirten bir kontrat gibidir” <em>Cihat Altuntaş</em> <a href="http://www.cihataltuntas.com/interface-nedirne-zaman-kullanilir/">kaynak</a></p><p>Bir <strong>Cache</strong> objesi yazdığınızı düşünün bu objenin 2 adet fonksiyonu var <strong>Set</strong> ve <strong>Get</strong> tahmin edeceğiniz üzere <strong>Set</strong> data kaydetmek <strong>Get</strong> ise data almak için kullanılacak. Cache bilgileride memory’de tutulacak.Sınıfın adı da <strong>MemoryCache</strong> yapalım ve kodlamaya başlayalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5881e909918488aef2a8dfcd780f3eb3/href">https://medium.com/media/5881e909918488aef2a8dfcd780f3eb3/href</a></iframe><p>Kodun çalışan haline <a href="https://play.golang.org/p/YYedDbQeoq"><strong>buradan</strong></a> ulaşabilirsiniz.</p><p>Kodu yazdıktan sonra projenize dahil ettiniz tüm cache gereken yerlerde ilgili kodu çağırıp ayarladınız çokta güzel çalıştı fakat belirli bir zaman sonra <strong>cache</strong>’teki dataları <strong>redis</strong>’te saklamayı düşündünüz tekrar bir sınıf yazdınız.Bu kez adınıda <strong>RedisCache</strong> yaptınız şimdi yapmanız gereken tüm kodları revize etmek bulup değiştirmek.</p><p>Aradan zaman geçti memcache ve database içinde implementasyon yazdınız.Fakat bunun sonu yok ve kod taşınabilir değil her cache provider’ını değiştiğinizde kodunuzu revize etmeniz gerekiyor ve kodunuz <strong>taşınabilir değil</strong> . Projeden örnek bir kod.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8210b64a50dc3e8528ea23fc562a4b0c/href">https://medium.com/media/8210b64a50dc3e8528ea23fc562a4b0c/href</a></iframe><p>Bu kodu yeni provider’e uyarlamak için editör de “<strong><em>find and replace</em></strong>” ile <strong>MemoryCache</strong> ile <strong>RedisCache </strong>kelimelerini değiştirebilirsiniz yada interface kullanabilirsiniz.</p><p>Örnek verecek olursak.</p><p>Bir tane sanal sınıf oluşturalım bilmeniz gereken interface’ler herhangi bir değer döndürmüyorlar sadece fonksiyon adlarını ve girdi,çıktı parametrelerini belirtiyorsunuz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4e9f6fc38ae3bc340e9846d14833264/href">https://medium.com/media/c4e9f6fc38ae3bc340e9846d14833264/href</a></iframe><p>Şimdi <strong>MemoryCache</strong> sınıfını <strong>interface</strong> kullanarak yeniden yazalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10d105e7bfb4b726d4dd365db100377d/href">https://medium.com/media/10d105e7bfb4b726d4dd365db100377d/href</a></iframe><p>Kodun çalışan haline <a href="https://play.golang.org/p/e5-7ANGODd">buradan</a> ulaşabilirsiniz.</p><p>Gördüğünüz gibi artık <strong>NewMemoryCache </strong>fonksiyonu artık <strong>Cache</strong> tipinde değer dönderiyor.Şimdi yazdığımız kodu kullanalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b089bd46e28a170d15ad418b93c7119/href">https://medium.com/media/7b089bd46e28a170d15ad418b93c7119/href</a></iframe><p>Şimdi tek yapmanız gereken projedeki kodunuzu <strong>Cache</strong> interface göre ayarlamak. Projede kodu kullandığınızda provider’e bakılmaksızın <strong>cache</strong> objesinin <strong>get</strong> ve <strong>set</strong> methodları kullanılabilinecek.Herhangi yeni bir provider eklemek istediğinizde Name,Set,Get fonksiyonlarını ve döndürecekleri parametreleri ayarlamanız yeterli.</p><p>Yazı interface kavramını anlatmakta ne kadar başarılı oldu bilmiyorum fakat özellikle golang’te uygulama yazarken girdi ve çıktılar için <a href="https://golang.org/pkg/io/#Reader">io.Reader</a>,<a href="https://golang.org/pkg/io/#Writer">io.Writer</a> kullanınca interface kullanımının kodunuzun ne kadar taşınabilir ve okunabilir yaptığını görünce çok seveceksiniz.</p><p>Yukarıdaki <strong>GetirOnu</strong> fonksiyonunun yeni hali şu şekilde olur</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85db82cbf2c2d9b312cfee1fe2350842/href">https://medium.com/media/85db82cbf2c2d9b312cfee1fe2350842/href</a></iframe><p>Gördüğünüz gibi <strong>GetirOnu</strong> fonksiyonu artık parametre olarak <strong>Cache interface</strong> alıyor ve <strong>cache provider</strong>in ne olduğu artık <strong>GetirOnu</strong> fonksiyonunu ilgilendirmiyor tek bildiği şey <strong>2. parametre</strong> ile gönderilen <strong>cache</strong> objesinin <strong>Get</strong> methodunun olduğu ve bu methodun 2 parametre dönderdiği ilk parametre value ikinci parametrede error dönderiyor.</p><p><strong>Gelecek Yazı İçin Not:</strong></p><p>Bir sonraki yazıda golang’in temel kütüphaneleriyle interface kullanımından bahsedeceğim.Aşağıdaki kod örneğinde fmt.Println fonksiyonun BaseModel objesinin String fonksiyonunu nasıl çağırdığına bakabilirsiniz.</p><pre>package main</pre><pre>import (<br> &quot;fmt&quot;<br>)</pre><pre>//BaseModel base model<br>type BaseModel struct {<br> name string<br>}</pre><pre>//String : php class&#39;taki toString fmt.Println bu fonksiyon varsa çağırır !!! interface !!<br>func (m *BaseModel) String() string {<br> return &quot;Name: &quot; + m.name<br>}<br>func main() {<br> base := &amp;BaseModel{name: &quot;Base Model Object&quot;}<br> fmt.Println(base)<br>}</pre><p>Kodun Çalışan haline buradan ulaşabilirsiniz: <a href="https://play.golang.org/p/FeYBAnVxt0">https://play.golang.org/p/FeYBAnVxt0</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9182db7ca5d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang Race Condition]]></title>
            <link>https://medium.com/@s4l1h/golang-race-condition-f60fe2e72da7?source=rss-43261ee2c8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f60fe2e72da7</guid>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[A.Kadir Mutlu]]></dc:creator>
            <pubDate>Fri, 09 Dec 2016 10:24:08 GMT</pubDate>
            <atom:updated>2016-12-09T10:24:08.224Z</atom:updated>
            <content:encoded><![CDATA[<p>Golang mutex race detection,race condition,sync.Mutex etc..</p><p>Golang’te uygulama yazarken <strong><em>concurrency</em></strong> gereken işlemler için <strong>goroutines</strong> kullanıyorsanız <a href="https://en.wikipedia.org/wiki/Race_condition#Software">race condition</a> problemi ile karşılaşabilirsiniz.Neden bahsediyorsun diyecek olanlar için örneklendirelim.</p><p>10.000 tane <strong>goroutines</strong> oluşturalım ve goroutines’lerin tek yapmaları gereken <strong>count</strong> değişkenini 1 arttırmaları.</p><blockquote>goroutines’lerin çalışmasını ve işlemlerini bitirmelerini garantilemek için sync.WaitGroup kullanalım.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55a4468c61fa29a5fe46e8db479459dd/href">https://medium.com/media/55a4468c61fa29a5fe46e8db479459dd/href</a></iframe><p>Bu kodu çalıştırdığınız her seferinde aşağıdaki gibi farklı sonuç alacaksınız.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*YxALSVZXGznk7D25eZRa7w.png" /></figure><p>Bunun sebebi <strong>goroutines</strong> kullandığımız için program <strong>synchronous</strong> çalışmıyor ve <strong>goroutines</strong>’ler çoğu zaman <strong>count</strong> değişkenine <strong><em>aynı anda</em></strong> müdahale ediyorlar ve buda <strong><em>race condition</em></strong> dediğimiz probleme neden oluyor.</p><p>Aynı şekilde <strong><em>go run -race 1.go </em></strong>ile de kodu çalıştırmak istediğinizde <strong>Race Detector </strong>hata bulacaktır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*dgSHml0bhTRG38gs4PvVeA.png" /></figure><p>Bu işi çözmek için gereken <strong>count</strong> değişkenine aynı anda erişilmesini engellemek.Bunun için kullanacağımız paket <a href="https://golang.org/pkg/sync/#Mutex">sync.Mutex</a></p><p>Kodu şimdi revize edelim ve <strong>count</strong> arttırılmadan önce <strong>lock</strong> arttırıldıktan sonrada <strong>unlock</strong> yapalım.Bu arada sync.Mutex’i <strong>Hit</strong> objemize embed edip öyle kullanalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c0ea2d089ba6c958c5a1159c5e3667a/href">https://medium.com/media/0c0ea2d089ba6c958c5a1159c5e3667a/href</a></iframe><p>Kodu çalıştırdığınızda artık aşağıdaki gibi bir çıktı verecektir ve <strong>Race</strong> <strong>Detector’</strong>den pass geçecektir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*RLpieaSsGeOFQDDpXT9EJQ.png" /></figure><p><strong><em>Concurrency </em></strong>gereken uygulamalarda mutlaka race condition dikkat edin ve bunun için go race dedektörünü kullanın.</p><p>“<strong>Yukardaki kodları </strong><a href="http://play.golang.org/"><strong><em>play.golang.org</em></strong></a><strong> adresinde denersiniz race hatası almazsınız.Bunun sebebi sandbox’ın bazı limitlerinin olması.GOMAXPROCS değeri 1 olarak set edilmiş.</strong>”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f60fe2e72da7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>