Skip to content

Instantly share code, notes, and snippets.

View kirshiyin89's full-sized avatar

Kirshi Yin kirshiyin89

View GitHub Profile
@kirshiyin89
kirshiyin89 / dataservice.dart
Created August 24, 2020 19:05
The DataService consuming the response from the back-end.
import 'package:myapp/serverinfo.dart';
import 'dart:js' as js;
import 'package:http/http.dart' as http;
import 'dart:async';
import 'dart:convert';
Future<List<ServerInfo>> fetchServerInfo() async {
final response = await http.get("http://localhost:8080/api");
if (response.statusCode == 200) {
@kirshiyin89
kirshiyin89 / main.dart
Last active August 25, 2020 13:28
The main application class.
import 'package:flutter/material.dart';
import 'package:myapp/dataservice.dart';
import 'dart:async';
import 'package:myapp/serverinfo.dart';
import 'package:myapp/startpage.dart';
void main() {
runApp(MyApp());
@kirshiyin89
kirshiyin89 / StartPage.dart
Last active August 25, 2020 13:29
The StartPage of the Flutter application holding the Grid Cards.
import 'package:flutter/material.dart';
import 'package:myapp/serverinfo.dart';
import 'package:myapp/serviceinfo.dart';
import 'package:myapp/utils.dart';
class StartPage extends StatelessWidget {
StartPage({Key key, this.title, this.serverInfo}) : super(key: key);
final String title;
final Future<List<ServerInfo>> serverInfo;
@kirshiyin89
kirshiyin89 / ServerInfo.dart
Last active August 25, 2020 13:31
The Server Info dto.
import 'package:myapp/serviceinfo.dart';
class ServerInfo {
const ServerInfo({this.name, this.services});
final String name;
final List<ServiceInfo> services;
factory ServerInfo.fromJson(Map<String, dynamic> json) {
@kirshiyin89
kirshiyin89 / ApiController.java
Last active August 25, 2020 13:32
The application's controller.
package com.serverchecker;
import com.serverchecker.dto.ServerInfo;
import com.serverchecker.service.DataService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class ApiController {
@kirshiyin89
kirshiyin89 / Api.java
Last active August 25, 2020 13:34
Spring boot main class
package com.serverchecker;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Api {
/**
* @param args the command line arguments
*/
@kirshiyin89
kirshiyin89 / DataService.java
Last active August 25, 2020 13:35
The DataService collecting the information from the server output file.
package com.serverchecker.service;
import com.serverchecker.dto.ServerInfo;
import com.serverchecker.dto.ServiceInfo;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
@kirshiyin89
kirshiyin89 / build.gradle
Created August 25, 2020 13:54
The gradle properties for Spring Boot.
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
@kirshiyin89
kirshiyin89 / application.properties
Last active August 25, 2020 15:43
The global application properties file.
datapath=./data
@kirshiyin89
kirshiyin89 / MessageReceiver.java
Created September 1, 2020 21:44
Create RabbitMQ connection
private Connection createConnection() throws TimeoutException, InterruptedException {
ConnectionFactory factory = new ConnectionFactory();
// "guest"/"guest" by default, limited to localhost connections
factory.setUsername("guest");
factory.setPassword("guest");
factory.setVirtualHost("/");
factory.setHost("127.0.0.1");
factory.setPort(5672);
return connectToRabbitMQ(factory);
}