Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

amocrm_auth

package main

import (
    "fmt"
    "bytes"
    "io/ioutil"
    "net/http"
)

func main() {
    url := "https://certitdev.amocrm.ru/private/api/auth.php?type=json"
    fmt.Println("URL:>", url)

    var jsonStr = []byte(`{"USER_LOGIN":"[email protected]","USER_HASH":"310b7548f578c050856fd92a59d0e73d6414ec6b"}`)
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
    req.Header.Set("Content-Type", "application/json")
    
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("response Status:", resp.Status)
    fmt.Println("response Headers:", resp.Header)
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println("response Body:", string(body))
}

Basic-Arrays

package main

import "fmt"

func main() {
    var arr[5] int
    arr = [5] int{1,2,3,4,5}
    fmt.Println(arr)
}

Constants

package main

import "fmt"

func main() {
   const LENGTH int = 10
   const WIDTH int = 5   
   var area int

   area = LENGTH * WIDTH
   fmt.Printf("value of area : %d", area)   
}

test

package main

import (
	"bytes"
	"crypto/aes"
	"crypto/cipher"
	"encoding/base64"
	"errors"
	"fmt"
	"time"
	"strings"
    "strconv"
    "net/http"
	"io/ioutil"
)

const aesIvDefValue = "d846ea815f80c3a8" // change it 
const aesKeyDefValue = "a0530e3d4edf934c" // change it 

func main() {
    
    // Action 11:required parameter information
    dc := "CT2"
    uid := "ct2tmppl01"
	data := "{\"action\":11, \"ts\":"+strconv.Itoa(int(time.Now().UnixNano() / 1000000))+", \"uid\": \""+uid+"\", \"lang\":\"ch\", \"gType\":\"0\", \"mType\":\"8001\", \"windowMode\":2}"
	fmt.Println("data:", data)

    // encrypt data
	encbyte, _ := AesEncrypt([]byte(data), checkAesKey(aesKeyDefValue))
	encryptString := strings.Replace(base64.StdEncoding.EncodeToString(encbyte), "+", "-", -1)
	fmt.Println("afterEncode:", encryptString)


	//decodeBytes, _ := base64.StdEncoding.DecodeString(encodeString)
	//decbyte, _ := AesDecrypt(decodeBytes, checkAesKey(aesKeyDefValue))
	//fmt.Println("afterDecode:", string(decbyte[:]))
	
	// check environment Settings file
	apiURL := "https://api.jdb711.com/apiRequest.do"

	payload := strings.NewReader("dc=" + string(dc) + "&x=" + encryptString)

    // post 
	req, _ := http.NewRequest("POST", apiURL, payload)

	req.Header.Add("content-type", "application/x-www-form-urlencoded")
	req.Header.Add("cache-control", "no-cache")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	//parse json and use the path url to login game
	fmt.Println(string(body))
}

func checkAesKey(strKey string) []byte {
	keyLen := len(strKey)
	arrKey := []byte(strKey)
	if keyLen >= 32 {
		return arrKey[:32]
	}
	if keyLen >= 24 {
		return arrKey[:24]
	}
	if keyLen >= 16 {
		return arrKey[:16]
	}
	tmp := make([]byte, 16)
	for i := 0; i < 16; i++ {
		if i < keyLen {
			tmp[i] = arrKey[i]
		} else {
			tmp[i] = '0'
		}
	}
	return tmp
}

func AesEncrypt(plaintext []byte, key []byte) ([]byte, error) {
	block, err := aes.NewCipher(key)
	if err != nil {
		fmt.Println("err=", err)
		return nil, errors.New("invalid decrypt key")
	}
	blockSize := block.BlockSize()
	plaintext = PKCS5Padding(plaintext, blockSize)
	iv := []byte(aesIvDefValue)
	blockMode := cipher.NewCBCEncrypter(block, iv)

	ciphertext := make([]byte, len(plaintext))
	blockMode.CryptBlocks(ciphertext, plaintext)

	return ciphertext, nil
}

func AesDecrypt(ciphertext []byte, key []byte) ([]byte, error) {

	block, err := aes.NewCipher(key)
	if err != nil {
		return nil, errors.New("invalid decrypt key")
	}

	blockSize := block.BlockSize()

	if len(ciphertext) < blockSize {
		return nil, errors.New("ciphertext too short")
	}

	iv := []byte(aesIvDefValue)
	if len(ciphertext)%blockSize != 0 {
		return nil, errors.New("ciphertext is not a multiple of the block size")
	}

	blockModel := cipher.NewCBCDecrypter(block, iv)

	plaintext := make([]byte, len(ciphertext))
	blockModel.CryptBlocks(plaintext, ciphertext)
	plaintext = PKCS5UnPadding(plaintext)

	return plaintext, nil
}

func PKCS5Padding(src []byte, blockSize int) []byte {
	padding := blockSize - len(src)%blockSize
	padtext := bytes.Repeat([]byte{byte(padding)}, padding)
	return append(src, padtext...)
}

func PKCS5UnPadding(src []byte) []byte {
	length := len(src)
	unpadding := int(src[length-1])
	return src[:(length - unpadding)]
}

fdsfdsfds

package main

import "fmt"

func main() {
   fmt.Printf("hello, world\n")
}

Execute GO Language Online

package main

import "fmt"

func main() {
   fmt.Printf("hello, world\n")
}

Execute GO Language Online

package main

import (
	"strconv"
	"fmt"
	"os"
	"bufio"
	"io"
)

func main() {
    readFile()
}

func sumOfSquares(strArray []string, iterate, currentSum int) int {
    var sum_of_squares = 0
    fmt.Println(strArray[iterate])
    number, _ := strconv.Atoi(strArray[iterate])
    
    if number > 0 {
         sum_of_squares += number * number
        return sumOfSquares(strArray, iterate+1, sum_of_squares)
    }
    return sumOfSquares(strArray, iterate+1, sum_of_squares)
}

func readFile() {
    var strArr []string
    reader := bufio.NewReader(os.Stdin)
    for {
        line, _, err := reader.ReadLine()

        if err == io.EOF {
            break
         }

        strArr = append(strArr, fmt.Sprintf("%s \n", line))
        fmt.Println(strconv.Atoi(fmt.Sprintf("%s \n", line)))
        sumOfSquares(strArr, 0, 0)
    }
}

Execute GO Language Online

package main

import (
	"fmt"
	"math"
	"math/rand"
	"time"
)

func numbers(sz int) (res chan float64) {
	res = make(chan float64)
	go func() {
		defer close(res) 
		num := 0.0
		time.Sleep(time.Duration(rand.Intn(1000)) * time.Microsecond)
		for i := 0; i < sz; i++ {
			num += math.Sqrt(math.Abs(rand.Float64()))
		}
		num /= float64(sz)
		res <- num
		return
	}()
	return
}

func main() {
	var nGo int
	rand.Seed(42)
	fmt.Print("Number of Go routines: ")
	fmt.Scanf("%d \n", &nGo)
	res := make([]chan float64, nGo)

	for i := 0; i < nGo; i++ {
		res[i] = numbers(1000)
		fmt.Print("\n", <- res[i])
	}

}

19/01/24

package main

import "fmt"

func main() {
   fmt.Printf("hello, world2\n")
   fmt.Printf("return is %d", f(3, 2) )
}

func f(x int, y int) int {
    z := 0
    if x > 0 {
        fmt.Printf("x%d >= 0 なのでf(x%d-1, y)呼び出し\n", x, x)
        z = f(x-1, y)
    }
    fmt.Printf("x = %d\n", x)
    fmt.Printf("%d+%d+%d = %d\n", x, y, z, x+y+z)
    return x+y+z
}

testme

package main

import "fmt"

func main() {
   /* This is my first sample program. */
   fmt.Println("Hello, World!")
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.